Working on an application involving arrays of coordinates, I encountered an interesting issue. When I try to log the points of a feature to the console, I receive an array containing 5 coordinate pairs:
var poly = data.features[0].geometry.coordinates
console.log(poly)
https://i.sstatic.net/UABcNm.png
However, if I attempt to exclude the last element of the array using the slice()
method - which should result in 4 elements instead of 5 - I end up with an empty array being returned:
var poly = data.features[0].geometry.coordinates.slice(0, -1);
console.log(poly)
https://i.sstatic.net/NCtXem.png
This raises the question: why does this unexpected behavior occur and what could be causing the slice()
method not to work as expected in this scenario?