Skip to content

Instantly share code, notes, and snippets.

@Jaballadares
Created January 9, 2019 22:31
Show Gist options
  • Save Jaballadares/eac2557fcbab90409982748e80c11b64 to your computer and use it in GitHub Desktop.
Save Jaballadares/eac2557fcbab90409982748e80c11b64 to your computer and use it in GitHub Desktop.
Find an Object in Array by String in One of its Properties
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