Skip to content

Instantly share code, notes, and snippets.

@mie00
Created December 23, 2015 11:32
Show Gist options
  • Save mie00/392f4145cea91ec791c2 to your computer and use it in GitHub Desktop.
Save mie00/392f4145cea91ec791c2 to your computer and use it in GitHub Desktop.
JavaScript object deep search
function searchDeep(obj,query,objName){
var a = []
var b = function(obj,query,c){
if(~(a.indexOf(obj))) return []
a.push(obj)
var d = []
if(query in obj){
d.push(c)
}
for(var j in obj){
if(obj[j] && typeof(obj[j]) === 'object'){
d = d.concat(b(obj[j],query,c+'.'+j))
}
}
return d
}
return b(obj,query,objName || '')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment