Skip to content

Instantly share code, notes, and snippets.

@edankwan
Created January 29, 2013 15:38
Show Gist options
  • Save edankwan/4665172 to your computer and use it in GitHub Desktop.
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.
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