Skip to content

Instantly share code, notes, and snippets.

@medric
Created March 7, 2017 17:03
Show Gist options
  • Select an option

  • Save medric/b95fab9a1946f7dc84d78fd5654b1c86 to your computer and use it in GitHub Desktop.

Select an option

Save medric/b95fab9a1946f7dc84d78fd5654b1c86 to your computer and use it in GitHub Desktop.
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