我需要做一個JS數組一樣無法讓數組的數組在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',因此我不能用於循環等。
請告訴我在做什麼錯?
「searchLocations」的定義在哪裏? – abhishekkannojia
'searchLocations'正在從db結果返回,並且可以成功調用爲searchResults [i] .name,'searchResults [i] .latitude','searchResults [i]。longitude','searchResults [i] .zm'。 它只是運行'console.log(searchLocations.length);'給出'0'。 –
你能編輯你的問題併發布searchResults嗎? –