Skip to content

Instantly share code, notes, and snippets.

@yarkovaleksei
Created November 10, 2017 12:55
Show Gist options
  • Save yarkovaleksei/f166cf6b74c83fbcf868ab7aec4959b0 to your computer and use it in GitHub Desktop.
Save yarkovaleksei/f166cf6b74c83fbcf868ab7aec4959b0 to your computer and use it in GitHub Desktop.
function recursive (obj, tab = '') {
let keys = []
try {
keys = Object.keys(obj)
} catch (err) {
throw new Error(err)
}
keys.forEach((key) => {
if (obj[key] !== null
&& typeof obj[key] === 'object') {
console.log('%s: =>', key)
recursive(obj[key], ' ')
} else {
console.log('%s%s: %s', tab, key, obj[key])
}
})
}
recursive({
a: 1,
b: 'bbb',
c: {
ac: 1,
bc: 'bcbcbc'
},
d: [1, 2]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment