Skip to content

Instantly share code, notes, and snippets.

@Clickys
Created October 28, 2018 14:34
Show Gist options
  • Save Clickys/2cde121fc965ac9b10cfc85e5f21cee6 to your computer and use it in GitHub Desktop.
Save Clickys/2cde121fc965ac9b10cfc85e5f21cee6 to your computer and use it in GitHub Desktop.
function loopObj(obj, valueToFind) {
for (let prop in obj) {
// Base Case:
if (obj[prop] === valueToFind) {
return obj[prop];
}
// Recursive Case:
if (typeof obj[prop] === 'object') {
return loopObj(obj[prop], valueToFind);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment