I have a nested array that holds a handful of coordinates. I am trying to loop the nested array and log the values of each coordinate.
I can get it working in Python, but I need it in JavaScript. Here is how it works in python:
list_of_coordinates = [(100, 98), (200, 78)]
for i in list_of_coordinates:
x_coord = i[0]
y_coord = i[1]
print(x_coord, y_coord)
The output of the above is:
100 98
200 78
When I try to do this in Javascript I get the output of 0 and 1... not the actual coordinate values.
let listOfCoordinates = [[100, 0], [200, 1]];
for (const i in listOfCoordinates) {
let xCoord = i[0];
let yCoord = i[1];
console.log(xCoord, yCoord);
}
The output of this is
0 undefined
1 undefined
listOrCoordinates.forEach(coord => console.log(coord[0], coord[1]));would also do the same thing