I've got what I'm assuming is a fairly simple javascript problem, but it's baffling me. Basically, I'm unable to access the properties inner properties of nested object literals within a for loop. I'd love if someone oculd explain to me why this doesn't work:
var object = {
"foo":{
propertyOne : "One",
propertyTwo : "Two"
},
"bar":{
propertyOne : "Three",
propertyTwo : "Four"
}
};
//This correctly returns "One"
window.alert(object.foo.propertyOne);
for(var m in object)
{
//this returns foo followed by bar
window.alert(m);
//This returns undefined
window.alert(m.propertyOne);
}
I think this illustrates the problem well enough. Why do I get undefined when I try to access the properties of the inner objects within the loop? I assume I'm missing something really simple here.
Thanks for reading.