Can anyone please help me break down these code and explain in detail why it returns 0 and 1?
For in statement is supposed to return the property of an object. I could not figure out why this code return 0 and 1. Can anyone explain in plain language? Thanks in advance for any help!
var JSON = {
"users":[
{
"name":"dennis",
"age":25
},
{
"name":"zoe",
"age":25
}
]
};
for (var prop in JSON.users){
console.log(prop);
}
Because
JSON.usersis an array, the keys are the indexes, 0 and 1 (you can retrieve the elements usingJSON.users[0]andJSON.users[1]).