A
Adam
I'm trying to retrieve some values from a json object, but instead it's
giving me the property name. For example:
var json = { "glossary": { "title": "example glossary" } };
console.log(json);
alert(json.glossary.title);
for (var x in json) { console.log(x); alert(x.title); }
This will show me the json object in the console with glossary and
title underneath it. When the alert for json.glossary.title fires, it
will show me "example glossary". however, inside of the for loop, I
see "glossary" in the console log (instead of the glossary object) and
undefined for the x.title alert.
What's going on? Could someone please explain why it's behaving this
way?
giving me the property name. For example:
var json = { "glossary": { "title": "example glossary" } };
console.log(json);
alert(json.glossary.title);
for (var x in json) { console.log(x); alert(x.title); }
This will show me the json object in the console with glossary and
title underneath it. When the alert for json.glossary.title fires, it
will show me "example glossary". however, inside of the for loop, I
see "glossary" in the console log (instead of the glossary object) and
undefined for the x.title alert.
What's going on? Could someone please explain why it's behaving this
way?