Created
April 13, 2021 11:49
-
-
Save vicainelli/c44a0622742cac00457afce0dd6fc3bb to your computer and use it in GitHub Desktop.
loop through nested json object javascript recursive
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 nestedLoop(obj) { | |
const res = {}; | |
function recurse(obj, current) { | |
for (const key in obj) { | |
let value = obj[key]; | |
if(value != undefined) { | |
if (value && typeof value === 'object') { | |
recurse(value, key); | |
} else { | |
// Do your stuff here to var value | |
res[key] = value; | |
} | |
} | |
} | |
} | |
recurse(obj); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment