配列を作成するJavascriptを作成しようとしています。 が配列の内部にある場合、構文は厳密になります。これは、MapViewerによって構文解析される必要があるためです。 しかし、私はいつも私の配列に要素をプッシュする理由を見つけることができないようです、この要素は引用符を持っていますか?ここでJavascript unshiftメソッドが引用符を追加するのはなぜですか?
は私のコードです:
var i = 0;
var j = 0;
var tempMarkers = [];
while (clusters.length - i > 0) {
if (i % 3 == 0) {
for (j = 0; j < clusters[i].length; j++) {
tempMarkers.unshift("{latitude:" + tempLocationsArray[clusters[i][j]][1] + ",longitude:" +
tempLocationsArray[clusters[i][j]][0] + ",tintColor: MapView.PinColors.GREEN}");
}
} else if (i % 3 == 1) {
for (j = 0; j < clusters[i].length; j++) {
tempMarkers.unshift("{latitude:" + tempLocationsArray[clusters[i][j]][1] + ",longitude:" +
tempLocationsArray[clusters[i][j]][0] + ",tintColor: MapView.PinColors.RED}");
}
} else {
for (j = 0; j < clusters[i].length; j++) {
tempMarkers.unshift("{latitude:" + tempLocationsArray[clusters[i][j]][1] + ",longitude:" +
tempLocationsArray[clusters[i][j]][0] + ",tintColor: MapView.PinColors.PURPLE}");
}
}
i++;
}
console.log(tempMarkers);
そして、これは私がコンソールに表示するものである。
["{latitude:37.33182081,longitude:-122.03038642,tintColor: MapView.PinColors.RED}",
"{latitude:37.33178632,longitude:-122.0306262,tintColor: MapView.PinColors.GREEN}",
"{latitude:37.33162007,longitude:-122.03070577,tintColor: MapView.PinColors.PURPLE}",
"{latitude:37.33142585,longitude:-122.03072774,tintColor: MapView.PinColors.RED}",
"{latitude:37.33124551,longitude:-122.03073664,tintColor: MapView.PinColors.GREEN}",
"{latitude:37.33108059,longitude:-122.03068245,tintColor: MapView.PinColors.PURPLE}",
"{latitude:37.33091383,longitude:-122.03061321,tintColor: MapView.PinColors.RED}",
"{latitude:37.3307498,longitude:-122.03054302,tintColor: MapView.PinColors.GREEN}",
"{latitude:37.33069778,longitude:-122.03035543,tintColor: MapView.PinColors.PURPLE}",
"{latitude:37.33067203,longitude:-122.03018068,tintColor: MapView.PinColors.RED}",
"{latitude:37.33067784,longitude:-122.02998825,tintColor: MapView.PinColors.GREEN}",
"{latitude:37.33068906,longitude:-122.02976028,tintColor: MapView.PinColors.PURPLE}",
"{latitude:37.33070167,longitude:-122.02952527,tintColor: MapView.PinColors.RED}",
"{latitude:37.33045837,longitude:-122.02866686,tintColor: MapView.PinColors.GREEN}",
"{latitude:37.32795258,longitude:-122.01982651,tintColor: MapView.PinColors.PURPLE}",
"{latitude:37.32465631,longitude:-122.02308996,tintColor: MapView.PinColors.RED}",
"{latitude:37.32632152,longitude:-122.02614004,tintColor: MapView.PinColors.GREEN}",
"{latitude:37.33070542,longitude:-122.02915124,tintColor: MapView.PinColors.PURPLE}",
"{latitude:37.33019844,longitude:-122.02479669,tintColor: MapView.PinColors.RED}",
"{latitude:37.32463343,longitude:-122.0228739,tintColor: MapView.PinColors.GREEN}"
]
は、あなたが、私はこれらの引用符を持っている理由を参照していますか?
あなたの配列は、引用符が含まれていませんが、それは、文字列含まれない - 引用符でコンソールに表示されているので...もちろん – nnnnnn
を、あなたは@nnnnnnありがとう! – Custam