I have an ajax request which loads a JSON file and parses it by storing a reference to the object. I'm trying to find a way in which I can loop through the object but due to it's structure I get errors on the console.
Here is an example of the JSON that I am parsing:
{
"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"
}
]
}
}
I have tried the following js loop, but I can't seem to get it to work correctly. (N.B. the object retrieved from parsing the JSON is referenced as markers.
markers.forEach(function(marker) {
console.log(marker.name);
});