Created
March 15, 2016 09:40
-
-
Save binaryreverse/1e5038efa16c71454bb5 to your computer and use it in GitHub Desktop.
JS Object inspection (Q&D)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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