Can't fix my script to log the way I need it

后端 未结 2 993

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

2条回答
  •  佛祖请我去吃肉
    2020-12-22 07:43

    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
    });
    

提交回复
热议问题