Reputation: 10601
I am getting a broken json:
Array(1), "40.7197406, 8.563512299999957", "40.7272074, 8.575266499999998", Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1)]
0: ["-22.91401497538739,-68.19866465000001"]
1: ["-25.857842171488155,-54.4140132"]
I tried JSON.parse(data[i].coordinates[i])
but I get that error, the json looks like has some strings but i'm not sure how to fix and make it correct
Upvotes: 0
Views: 558
Reputation: 782295
That's not JSON, so don't try to use JSON.parse
. Just split it on the commas and call parseFloat()
.
var data = [{
coordinates: ["40.7197406, 8.563512299999957", "40.7272074, 8.575266499999998"]
}];
var coords = data[0].coordinates.map(s => s.split(",").map(n => parseFloat(n.trim())));
console.log(coords);
Upvotes: 1