Created
January 25, 2014 20:27
-
-
Save dvdbng/8623061 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 getAllProperties(obj){ | |
var allProps = Object.getOwnPropertyNames(obj); | |
Object.getOwnPropertyNames(Object.getPrototypeOf(obj)).forEach(function add(prop){ | |
if (allProps.indexOf(prop) === -1) | |
allProps.push(prop) | |
}); | |
return allProps | |
} | |
function jsrecursivegrep(obj, value, length){ | |
var res = []; | |
if(length == 0) return res; | |
getAllProperties(obj).forEach(function(k){ | |
try{ | |
if(obj[k] == value){ | |
res.push(k); | |
}else if(obj[k]){ | |
jsrecursivegrep(obj[k], value, length-1).forEach(function(prop){ | |
res.push(k + "." + prop); | |
}); | |
} | |
}catch(e){} | |
}); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment