I’m working on a function that pulls the lat/lng from an MVCArray of markers. The function is below. However, each object in the mapData array contains the prototype of the native object, along with lat/lng. I have played around with hasOwnProperty, but without much luck. Am I doing something obviously wrong here?
function prepareMarkers() {
var mapData = [];
// All we need from our markers list is the coordinates of the marker and title if it has one
markers.forEach(function(elem, index) {
mapData.push({
lat: elem.getPosition().lat(),
lng: elem.getPosition().lng()
});
});
return mapData;
}
You are putting native objects into the mapData array. That’s what this is. It’s an object.
So, it’s working exactly as it should. Since they are objects, they should have the methods from the prototype of the native object. Is there a particular problem you are trying to solve here? Everything you’ve described so far sounds correct.
In your array, you can just access things like this: