var employee = {
"firstName" : "Krishna",
"lastName" : "Majety",
"age" : 29,
"address" : {
"city" : "Bangalore",
"area" : "Marthalli"
}
}
function printProperties(object, objectName, tab){
var props = Object.keys(object);
for(i = 0; i < props.length; i++){
property = props[i];
if(object[property] instanceof Object){
printProperties(object[property], objectName+"."+property, " " + tab);
}else{
console.log(tab + objectName + "." + property + " => " + object[property]);
}
}
}
printProperties(employee, "employee", "")
如果有人能解释这种行为的原因,那就太好了。