I am experiencing an issue with a function that is supposed to assign an object inside a two-dimensional array. However, the assignment seems to be overwriting the previous object in the array.
var markersN = {};
var markersNArray = []
function addMarkerN(lat, lng, id, name, key) {
markersN[key] = {};
var newMark = new google.maps.Marker({
/*marker properties*/
});
markersNArray.push(newMark); //This successfully pushes every object to a one-dimensional array
markersN[key][id] = newMark; //However, this line replaces the previous object in the markersN[key] array
}
This is how I invoke the function:
for(var j=0; j<sekolah[i].nonlat.length; j++){
addMarkerN(sekolah[i].nonlat[j], sekolah[i].nonlon[j], j, sekolah[i].nonname[j], sekolah[i].key);
}
This is the desired structure of the array:
Array
(
[0] => Array
(
[0] => { /*marker object*/ }
[1] => { /*marker object*/ }
)
)
However, this is the actual resulting array structure:
Array
(
[0] => Array
(
[1] => { /*marker object*/ }
)
)
I would like guidance on what I might be doing wrong and how I can prevent the function from overwriting the previous object in the array. Thank you.