简体   繁体   English

javascript - 在多维数组上添加一个值

[英]javascript - add a value on multidimensional array

I am developing a website with bing map.我正在开发一个带有 bing map 的网站。 I've almost done it, but i want to have the pin clustering functionalitty.我几乎完成了,但我想拥有 pin 集群功能。 Then i got this code from the internet:然后我从网上得到了这段代码:

var data = [
        { "latitude": 59.441193, "longitude": 24.729494 },
        { "latitude": 59.432365, "longitude": 24.742992 },
        { "latitude": 59.431602, "longitude": 24.757563 },
        { "latitude": 59.437843, "longitude": 24.765759 },
        { "latitude": 59.439644, "longitude": 24.779041 },
        { "latitude": 59.434776, "longitude": 24.756681 }
    ];

I can get the latitude and longitude of every pushpin on my map, but i don't know how to add the latitude and longitude on this array.我可以在我的 map 上获得每个图钉的纬度和经度,但我不知道如何在这个数组上添加纬度和经度。 Can anyone help me?谁能帮我?

data.push({"latitude": lat, "longitude": lng});

Another way is using the spread operator.另一种方法是使用扩展运算符。


let data = [
        { "latitude": 59.441193, "longitude": 24.729494 },
        { "latitude": 59.432365, "longitude": 24.742992 },
        { "latitude": 59.431602, "longitude": 24.757563 },
        { "latitude": 59.437843, "longitude": 24.765759 },
        { "latitude": 59.439644, "longitude": 24.779041 },
        { "latitude": 59.434776, "longitude": 24.756681 }
    ];

data = [...data, {"latitude": lat, "longitude": lng}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM