I have this array that I add objects to:
waypts.push({location: location.lat() + "," + location.lng()});
How can I get the literal value it saves?
With Object.value
and valueOf
do not do what I intend
I have this array that I add objects to:
waypts.push({location: location.lat() + "," + location.lng()});
How can I get the literal value it saves?
With Object.value
and valueOf
do not do what I intend
I think the cleanest thing would be to use map :
waypts = [{location:"32.34,75.34"}]
waypts.push({location: "48.68" + "," + "92.34"});
var names = waypts.map(function(item) {
return item['location'];
});
console.log(names[0]);
console.log(names[1]);
console.log(waypts[0].location);
console.log(waypts[1].location);
Edit : After the comment of @LPZadkiel I leave your solution here to make it more visible. You can directly access the location property of the object like this:
waypts[0].location