Created
January 29, 2013 15:38
-
-
Save edankwan/4665172 to your computer and use it in GitHub Desktop.
A function to allow expanding the object/array in console. NOT working on dom elements or functions as I use JSON.stringify.
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
if (window.console && window.JSON) console.expand = function () { | |
var i, j; | |
var output = ''; | |
var str = JSON.stringify(arguments); | |
var pos = 0; | |
var len = str.length; | |
var indent = ' '; | |
var newLine = '\n'; | |
var char = ''; | |
for (i = 0; i < len; i++) { | |
char = str.substr(i, 1); | |
if (char == '}' || char == ']') { | |
output += newLine; | |
pos = pos - 1; | |
for (j = 0; j < pos; j++) { | |
output += indent; | |
} | |
} | |
output = output + char; | |
if (char == '{' || char == '[' || char == ',') { | |
output += newLine; | |
if (char == '{' || char == '[') { | |
pos = pos + 1; | |
} | |
for (j = 0; j < pos; j++) { | |
output += indent; | |
} | |
} | |
} | |
console.log(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment