pavlo pavlo - 1 month ago 8
Javascript Question

how to read value of object in array

I need to get the value of array of objects

Here is my part of googlemaps code which creates markers

var addMarker = function () {
geocoder.geocode({'address': address}, function (results, brigadeStatus) {
pic = 'images/red.png';
marker = new google.maps.Marker({
id: clientId,
map: map,
position: results[0].geometry.location,
title: "ID: " +clientId +"; " +clientStreet_char + ' ' + clientStreet_name + ' ' + clientStreet_adr,
icon: pic
});
}
clientMarkerId.push(marker);
clientMarkers[clientId] = marker;
});
};


After I have created three markers, I have opened console of chrome developer tools
where I have typed >clientMarkerId It shows array and three elements

> clientMarkerId
[_.ue, _.ue, _.ue]


Clicking on each element show this:

[__e3_:Object
click:Object
rightclick:Object
__proto__:Object
__gm:Object
anchorPoint:_.I
changed:(a)
clickable:true
closure_uid_596642721:375
gm_accessors_:Object
gm_bindings_:Object
icon:"images/red.png"
id:10
internalPosition:_.E
map:qg
position:_.E
title:"ID: 10; str. ABC 102"
visible:true
__proto__:qe]


Here is also an image

enter image description here

So, the question is how can I get the value of "icon" ("images/red.png") of any
clientMarkerId
array element?

Answer

Try clientMarkerId[0].icon?

Replace the 0 with the index of which one you need. Use a loop if you need to get all of them.

Comments