Created
November 25, 2012 13:02
-
-
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
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
// 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