Created
December 23, 2015 11:32
-
-
Save mie00/392f4145cea91ec791c2 to your computer and use it in GitHub Desktop.
JavaScript object deep search
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 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