Created
February 20, 2023 07:32
-
-
Save xtrmstep/2f5bb4f908a92f9ab1aa52ccd17fbdbb to your computer and use it in GitHub Desktop.
Object dump of an object during execution of JavaScript code
This file contains hidden or 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 odump(object, depth, max) { | |
depth = depth || 0; | |
max = max || 2; | |
if (depth > max) return false; | |
var indent = ""; | |
for (var i = 0; i < depth; i++) indent += " "; | |
var output = ""; | |
for (var key in object) { | |
output += "n" + indent + key + ": "; | |
switch (typeof object[key]) { | |
case "object": | |
output += odump(object[key], depth + 1, max); | |
break; | |
case "function": | |
output += "function"; | |
break; | |
default: | |
output += object[key]; | |
break; | |
} | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few spaces/newlines here and there in the output wouldn't hurt readability.