So this is really getting on my nerves. I needed to explain this a bit better so here it is. I\'m trying to make my script log in google\'s console a specific way. I\'ve got
Your code was almost there, but what you were logging to the console was ridiculous, since it was just the points attribute, unmodified
So, something like this
const polylines = Array.from(xmlDoc.getElementsByTagName('polyline'));
const Lines = polylines.map(pl => pl.getAttribute('points').split(' ').map(pair => pair.split(',').map(Number)));
Lines.forEach(line => console.log(JSON.stringify(line)));
Or, given that the second argument to Array.from is a map function, you can further simplify the code to
const Lines = Array.from(xmlDoc.getElementsByTagName('polyline'), pl => pl.getAttribute('points').split(' ').map(pair => pair.split(',').map(Number)));
Lines.forEach(line => console.log(JSON.stringify(line)));
Note, the console.log is done AFTER the processing
as for the comment
Lines.forEach(line => {
// here you can post each line to whatever you need
});
please try this, maybe this will work for you.
var dt = "346 453 346 452 346 452 346 453 346 453 347 453 347 453 347 454 348 454 349 454 350 454 351 454 352 454 353 454 354 454 354 453 355 452 355 453";
function fnGetObject(data) {
var objList = [];
var obList = data.split(' ');
var obResult = []
for (var i = 0; i < obList.length; i += 2) {
obResult.push([parseInt(obList[i]), parseInt(obList[i + 1])]);
}
return JSON.stringify(obResult);
}
console.log(fnGetObject(dt));