Skip to content

Instantly share code, notes, and snippets.

@binaryreverse
Created March 15, 2016 09:40
Show Gist options
  • Save binaryreverse/1e5038efa16c71454bb5 to your computer and use it in GitHub Desktop.
Save binaryreverse/1e5038efa16c71454bb5 to your computer and use it in GitHub Desktop.
JS Object inspection (Q&D)
function objInspect(o, i) {
if(typeof i == 'undefined') {
i = '';
}
if(i.length > 50) {
return '[MAX ITERATIONS]';
}
var r = [];
for(var p in o) {
var t = typeof o[p];
r.push(i + '"' + p + '" (' + t + ') => ' + (t == 'object' ? 'object:' + objInspect(o[p], i + ' ') : o[p] + ''));
}
return r.join(i + '\n');
}
// example of use:
console.debug(objInspect(myDataObj));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment