Get Object Array String

3

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

    
asked by Eduardo 05.04.2018 в 11:55
source

1 answer

6

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
    
answered by 05.04.2018 / 12:06
source