Skip to content

Instantly share code, notes, and snippets.

@vicainelli
Created April 13, 2021 11:49
Show Gist options
  • Save vicainelli/c44a0622742cac00457afce0dd6fc3bb to your computer and use it in GitHub Desktop.
Save vicainelli/c44a0622742cac00457afce0dd6fc3bb to your computer and use it in GitHub Desktop.
loop through nested json object javascript recursive
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