gpt4 book ai didi

javascript - 无法在JS中创建数组的数组

转载 作者:行者123 更新时间:2023-12-03 04:45:11 26 4
gpt4 key购买 nike

我需要制作一个像

这样的 JS 数组
var locations = [
['Erbil, Soran POS', 36.649415, 44.534143, 4],
['Duhok, Duhok', 36.867905, 42.948857, 4],
['Duhok, Akre', 36.700016, 43.920457, 4],
['Duhok, Zakho', 37.150462, 42.672677, 4],
['Duhok, Shiladze', 36.650648, 44.519263, 4],
['Duhok, Bardaresh', 36.650648, 44.519263, 4],
['Mosel, Sinjar', 36.314216, 41.862443, 4],
['Duhok, Duhok', 36.867905, 42.948857, 4],
['Duhok, Akre', 36.741121, 43.880849, 4],
['Duhok, Zakho', 37.150462, 42.672677, 4],
['Duhok, Shiladze', 36.650648, 44.519263, 4],
['Duhok, Bardaresh', 36.911505, 42.728491, 4],
['Duhok, Amadia', 37.091727, 43.487692, 4],
['Sulimanya, Sulimanya', 35.557045, 45.435943, 4],
['Sulimanya, Dirbendikan', 35.110939, 45.695271, 4],
];

我正在尝试这样:

var locations;
for (i = 0; i < searchResults.length; i++) {
locations = new Array(searchResults[i].name, searchResults[i].latitude, searchResults[i].longtitude, searchResults[i].zm);
searchLocations.push(locations)
}

但是它创建了一个包含数据的数组,但其长度为“0”,因此我不能使用 for 循环等。

请告诉我我做错了什么?

最佳答案

尝试以下操作

var searchLocations=[];
for (i = 0; i < searchResults.length; i++) {
var locations = new Array(searchResults[i].name, searchResults[i].latitude, searchResults[i].longtitude, searchResults[i].zm);
searchLocations.push(locations)
}

关于javascript - 无法在JS中创建数组的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42900143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com