I would like to understand what I did wrongly. I have tried to read this, but it was overwhelmingly detailed: Access / process (nested) objects, arrays or JSON
{
"dogs":[
{
"name": "shiba",
....
}
{
"name": "akita",
....
}
]
}
I read the JSON from an HTTP server and it was returned as data
.
for(var item in data["dogs"])
{
console.log(item["name"]);
console.log(data["dogs"][0]["name"]);
}
console.log(item["name"]);
does not work, returning 'undefined'. console.log(data["dogs"][0]["name"]);
works, but since it has a fixed index, it does not iterate all names. Why isn't the first one working?
In VS Code, if I set a breakpoint at that line, somehow the breakpoint does not stay. It gets hit but continues away in a second, so I cannot examine the data. Before running, if I place the mouse on item
, the popup says that the type is string
. Why is it a string; shouldn't it be 'any'?