Skip to content

Instantly share code, notes, and snippets.

@arpruss
Last active August 13, 2021 13:32
Show Gist options
  • Save arpruss/8efd70269e5562bda54a33524beec67d to your computer and use it in GitHub Desktop.
Save arpruss/8efd70269e5562bda54a33524beec67d to your computer and use it in GitHub Desktop.
function finder(obj, keyToFind, level=7, soFar='', searched=new Set) {
if (level<=0 || typeof obj != 'object' || obj === null || searched.has(obj)) return;
searched.add(obj)
if (keyToFind in obj) {
console.log(soFar + '.' + keyToFind)
}
for (let key in obj) {
try {
finder(obj[key], keyToFind, level-1, soFar + '.' + key, searched);
}
catch(e) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment