Created
January 9, 2019 22:31
-
-
Save Jaballadares/eac2557fcbab90409982748e80c11b64 to your computer and use it in GitHub Desktop.
Find an Object in Array by String in One of its Properties
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
const produce = [ | |
{ name: 'apples', quantity: 2 }, | |
{ name: 'bananas', quantity: 0 }, | |
{ name: 'cherries', quantity: 5 } | |
]; | |
function isCherries(fruit) { | |
return fruit.name === 'cherries'; | |
} | |
console.log(produce.find(isCherries)); | |
// { name: 'cherries', quantity: 5 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment