I've been struggling to extract data from an array of objects using pure javascript, but I'm just not seeing the results.
Issue Resolved!
A big shoutout for the invaluable personal assistance! Turns out, the array was being passed as a string and required parsing before iteration. Problem solved!
// Here is a sample of the array received by the function, which is not declared in this
// JS file but rather received as a parameter. I'm including it so you can see the format
// of the data received
[{
"id": 171659,
"latitude": "-51.195946",
"longitude": "-30.021810",
"estado": "INSTALLED"
},
{
"id": 171658,
"latitude": "-51.196155",
"longitude": "-30.021615",
"estado": "INSTALLED"
}
]
// My js file contains only the function that receives the data, shown below is the
// entire file. The array itself is not declared here; it's simply received by the function.
// Data is successfully received but having trouble iterating through
// ====== Get Array ======
function getArray(data) {
var json = JSON.parse(data); //The data comes in as a string, requiring parse()
for (var i = 0; i < json.length; i++) { // Issue: values are undefined
console.log(json[i].id);
}
}