Created
November 10, 2017 12:55
-
-
Save yarkovaleksei/f166cf6b74c83fbcf868ab7aec4959b0 to your computer and use it in GitHub Desktop.
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 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