Skip to content

Instantly share code, notes, and snippets.

@jeremija
Created December 1, 2013 08:38
Show Gist options
  • Save jeremija/7729929 to your computer and use it in GitHub Desktop.
Save jeremija/7729929 to your computer and use it in GitHub Desktop.
Recursive object traversal
function traverse(data) {
for (var objName in data) {
if (!data.hasOwnProperty(objName)) {
continue;
}
var obj = data[objName];
if (typeof obj === 'object') {
console.log('obj: ' + objName + ' = {}...');
this.traverse(obj);
continue;
}
if (typeof obj === 'function') {
obj = obj();
console.log('obj: ' + objName + '() = ' + obj);
continue;
}
console.log('obj: ' + objName + ' = ' + obj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment