Traverse object tree
Traverse object tree and print object properties
by Nirvanachain
JavaScript
var data = {
person: {
firstName: 'Mary'
},
color: 'blue'
};
function walk(root) {
for(var i in root) {
if(root.hasOwnProperty(i)) {
console.log(i);
debugger;
if ( root[i] !== null && root[i] !== undefined && (typeof root[i] === 'object') ) {
walk(root[i]);
}
}
}
}
walk(data);