Created
November 28, 2010 11:13
-
-
Save rummelonp/718835 to your computer and use it in GitHub Desktop.
ObjectやArrayを見やすく整形
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
var pp = function(object, offset) | |
{ | |
var indent = ' '; | |
offset = offset || ''; | |
var output = ''; | |
if (object.constructor === Array) { | |
output += '[\n'; | |
for (var i = 0, len = object.length; i < len; i += 1) { | |
output += offset + indent; | |
output += pp(object[i], offset + indent); | |
output += ',\n'; | |
} | |
output += offset + ']'; | |
} else if (object.constructor === Object) { | |
output += '{\n'; | |
for (var i in object) { | |
output += offset + indent; | |
output += pp(i) + ': ' + pp(object[i], offset + indent); | |
output += ',\n'; | |
} | |
output += offset + '}'; | |
} else { | |
output += '"' + object + '"'; | |
} | |
return output; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment