I have javascript object that contains nested objects. I want to iterate over these using a ‘for in’ loop but this returns a string instead of an object?
Code:
var myObject = {
myNestedObject : {
key1 : value 1
}
}
And then if i loop:
for(theObject in myObject){
alert(typeof theObject);
}
This returns the string ‘myNestedObject’ but not the object itself.
Why?
theObjectis the property key. What you want is probably: