Skip to content

Instantly share code, notes, and snippets.

@hsribei
Created November 25, 2012 13:02
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 hsribei/4143411 to your computer and use it in GitHub Desktop.
Save hsribei/4143411 to your computer and use it in GitHub Desktop.
Find a property that has a certain value and return its object path starting at the root object parameter
// FIXME: this can very rapidly hit the call stack size limit
function findPropertyValue(obj, value) {
if (typeof obj.seenBefore === "undefined") {
// treat for object graph circularity
obj.seenBefore = true;
for (var key in obj) {
if (obj[key] == value) {
return key;
} else {
if (obj[key]) {
var foundIt = findInput(obj[key], value);
if (foundIt) {
return key + '.' + foundIt;
}
}
}
}
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment