Created
January 17, 2019 19:05
-
-
Save pablocattaneo/84a2f01e79d6f29f1c3a412b1fec52bd to your computer and use it in GitHub Desktop.
How to get an element array by value in JavaScript? #JavaScript Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
This file contains hidden or 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 inventory = [ | |
{name: 'apples', quantity: 2}, | |
{name: 'bananas', quantity: 0}, | |
{name: 'cherries', quantity: 5} | |
]; | |
const result = inventory.find( fruit => fruit.name === 'cherries' ); | |
console.log(result) // { name: 'cherries', quantity: 5 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment