Created
March 7, 2017 17:03
-
-
Save medric/b95fab9a1946f7dc84d78fd5654b1c86 to your computer and use it in GitHub Desktop.
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
| const o = { | |
| foo:"bar", | |
| bar: { | |
| foo: "bar" | |
| }, | |
| a: [1, 2, 3], | |
| }; | |
| function traverse(json) { | |
| for (const key in json) { | |
| if (json.hasOwnProperty(key)) { | |
| const value = json[key]; | |
| console.log(key, value); | |
| if (typeof value === 'object') { | |
| traverse(value); | |
| } | |
| } | |
| } | |
| } | |
| traverse(o); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment