suppose I have a object:
obj:{
child:{
x:12,
y:50
},
key1:"value1",
key2:"value2"
}
if I want to traverse the object,like:
for (var i in obj) {
}
How can I judge whether the object have child object,so I could traverse it.I know I could use hasOwnProperty method, but in this situation, I have no idea about what the child object name is .
You can use this to check if a property contains an Object:
A note of precaution: remember that Functions and Arrays are both Objects in Javascript. You can test individually for those using
instanceof Functionandinstance of Array.