Last active
December 19, 2015 23:08
-
-
Save chrisparnin/6032323 to your computer and use it in GitHub Desktop.
Summarize JSON
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 sum = function(o, tabLevel){ | |
for(var prop in o){ | |
if(o.hasOwnProperty(prop)){ | |
var val = o[prop]; | |
var header = ""; | |
for( var t = 0; t < tabLevel; t++ ) | |
{ | |
header += '\t'; | |
} | |
console.log(header + prop + ":"); | |
if(typeof val == 'object'){ | |
sum(val, tabLevel+1); | |
} | |
} | |
} | |
}; | |
sum({ 'foo':'bar', biz: { x: 'y', nested: { z: [1,2,3,4] } } }, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: