I'm aware that properties in objects can be retrieved either .notation or wrapping key as a string expression in a [] suffix. for example
var character = {
"name" : "Gloria",
"feature" : "Dance"
};
console.log("using .notation: "+character.name);
console.log("using []suffix: "+character["name"]);
And it's works pretty well. But, When I do the same by retrieving values from an array of objects, .Notation is simply not working. The codes shows below.
var info = {
"full_name" : "Some Name",
"title" : "Some title",
"links" : [
{ "blog" : "http://iviewsource.com" },
{ "facebook" : "http://facebook.com/iviewsource" },
{ "youtube" : "http://www.youtube.com/planetoftheweb" },
{ "podcast" : "http://feeds.feedburner.com/authoredcontent" },
{ "twitter" : "http://twitter.com/planetoftheweb" }
]
};
then, when I try to retrieve values from each object in an array with the following snippet
for(var i = 0; i < info.links.length; i++) {
for(var key in info.links[i]) {
console.log("key is: "+key+" and it's value: "+info.links[i][key]);
}
}
In the above code, to retrieve the values I'm using info.links[i][key] and it's works as expected but if I use info.links[i].key, it just gives undefined which I'm not expected.
I wonder why? It confuses me a lot.