Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pablocattaneo/84a2f01e79d6f29f1c3a412b1fec52bd to your computer and use it in GitHub Desktop.
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
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