stevenbeales
1/14/2019 - 9:50 PM

Deep Search Javascript Object

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 || '')
}