Skip to content

Instantly share code, notes, and snippets.

@ZhihaoLau
Last active January 30, 2016 16:17
Show Gist options
  • Save ZhihaoLau/ebbcd501198cbec26f2b to your computer and use it in GitHub Desktop.
Save ZhihaoLau/ebbcd501198cbec26f2b to your computer and use it in GitHub Desktop.
Print a JavaScript object
var printObj = typeof JSON != 'undefined' ? JSON.stringify : function(obj) {
var arr = [];
$.each(obj, function(key, val) {
var next = key + ': ';
next += $.isPlainObject(val) ? printObj(val) : val;
arr.push(next);
});
return '{ ' + arr.join(', '); + ' }';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment