Node-red json parsing

Hello,
I am new to node-red and i have a Json file with multiple arrays:


and i want to iterate them all in a nested loop so i can save the values inside a list.
so far i managed to iterate one array and save the values to a list but i cannot go through multiple arrays for some reason
This is what i have so far:

for (var i=0; i<=data.features[0].geometry.coordinates.length; i++){
    for (var j=0; j<=data.features[0].geometry.coordinates[i].length; j++)
        spots.push(data.features[0].geometry.coordinates[i][j]);
}

and i get the following error:

TypeError: Cannot read property 'length' of undefined

Change the <= to < in the for loops.

You are going past the end of the array.

That worked! Thank you very much!

For future reference, there are much easier ways to iterate an array.

msg.payload.features.forEach( feature => {
  feature.geometry.coordinates.forEach( coord => {
    // .... and so on ....
  })
})

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.