Skip to content

Instantly share code, notes, and snippets.

@jq-87
Created September 19, 2019 12:48
Show Gist options
  • Save jq-87/e2a85b91e4adea5c3768e7068067054b to your computer and use it in GitHub Desktop.
Save jq-87/e2a85b91e4adea5c3768e7068067054b to your computer and use it in GitHub Desktop.
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