Skip to content

Instantly share code, notes, and snippets.

@Daniel-Hug
Created August 3, 2017 23:56
Show Gist options
  • Save Daniel-Hug/9fa867bd5e9790d14acc5642e24c74e6 to your computer and use it in GitHub Desktop.
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
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