Skip to content

Instantly share code, notes, and snippets.

@dvdbng
Created January 25, 2014 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdbng/8623061 to your computer and use it in GitHub Desktop.
Save dvdbng/8623061 to your computer and use it in GitHub Desktop.
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