Created
September 19, 2019 12:48
-
-
Save jq-87/e2a85b91e4adea5c3768e7068067054b to your computer and use it in GitHub Desktop.
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
function findByPropertyValue(object, propName, propValue) { | |
if (object[propName] === propValue) { | |
return object; | |
} | |
var result, property; | |
for (property in object) { | |
if ( | |
object.hasOwnProperty(property) && | |
typeof object[property] === "object" && | |
object[property] !== null | |
) { | |
result = findByPropertyValue(object[property], propName, propValue); | |
if (result) { | |
return result; | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment