If I have an array that looks like this;
markers[56] = { label: "One" };
markers[62] = { label: "Two" };
markers[87] = { label: "Three" };
markers[125] = { label: "Four" };
Now I have some JS;
for (var thisMarker in markers) {
//What goes here so I can access the "label" property?
}
I know this is simplistic but later on there will be many more properties added to the object not just "label".
asked Jun 5, 2012 at 3:32
griegs
22.8k33 gold badges133 silver badges208 bronze badges
2 Answers 2
I believe you can access it like this,
for (var thisMarker in markers) {
alert(markers[thisMarker].label);
}
answered Jun 5, 2012 at 3:34
Rich Adams
26.7k4 gold badges43 silver badges62 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
for(var thisMarker in markers){
//this will give you the label- markers[thisMarker].label
}
answered Jun 5, 2012 at 3:38
Subir Kumar Sao
8,4393 gold badges28 silver badges51 bronze badges
Comments
lang-js