Created
August 3, 2017 23:56
-
-
Save Daniel-Hug/9fa867bd5e9790d14acc5642e24c74e6 to your computer and use it in GitHub Desktop.
JS function: Create a string representation of a (nested) object for logging purposes
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 displayProps(obj, indent) { | |
indent = indent || '\t'; | |
var str = ({}).toString.call(obj).slice(8,-1) + ':\n'; | |
for (var key in obj) { | |
var val = typeof obj[key] === 'object' ? | |
displayProps(obj[key], indent + '\t') : obj[key]; | |
str += indent + key + ': ' + val + '\n'; | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment