Last active
January 30, 2016 16:17
-
-
Save ZhihaoLau/ebbcd501198cbec26f2b to your computer and use it in GitHub Desktop.
Print a JavaScript object
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
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