Created
July 12, 2012 22:30
-
-
Save johnryan1982/3101506 to your computer and use it in GitHub Desktop.
Quick and dirty JS Object iterator
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
function iterate( data ) | |
{ | |
if( typeof data === typeof {} ) | |
{ | |
for( i in data ) | |
{ | |
if( data.hasOwnProperty( i ) ) | |
{ | |
console.log( i, data[i] ); | |
iterate( data[i] ); | |
} | |
} | |
} | |
} | |
obj = { user: { name:'john', id:30 } } | |
iterate( obj ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment