After making an ajax request to load a JSON file and parsing it to store a reference to the object, I encountered issues while trying to loop through the object due to its structure.
Below is a snippet of the JSON data that I am working with:
{
"markers": {
"marker": [
{
"name": "john",
"latitude": "53.4682282",
"longitude": "-2.238547"
},
{
"name": "david",
"latitude": "53.4663409",
"longitude": "-2.2328164"
},
{
"name": "mathew",
"latitude": "53.4668135",
"longitude": "-2.2310998"
}
]
}
}
Despite attempting the following JavaScript loop, I have been unable to execute it successfully. (Note: the object derived from parsing the JSON is named markers
.)
markers.forEach(function(marker) {
console.log(marker.name);
});