-
-
Save dinh/d13e7b0fb21b26310fe40b65073db9af to your computer and use it in GitHub Desktop.
Recursively traverse object javascript, recurse json js, loop and get key/value pair for JSON
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 traverse = function(o, fn) { | |
| for (var i in o) { | |
| fn.apply(this,[i,o[i]]); | |
| if (o[i] !== null && typeof(o[i])=="object") { | |
| traverse(o[i], fn); | |
| } | |
| } | |
| } | |
| // usage | |
| var obj = {'your':'object'}; | |
| traverse(obj, function(k,v){ | |
| console.log(k + " : " + v); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment