array method that returns undefined code example
Example 1: javascript find
const inventory = [
{name: 'apples', quantity: 2},
{name: 'cherries', quantity: 8}
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
{name: 'cherries', quantity: 15}
];
const result = inventory.find( ({ name }) => name === 'cherries' );
console.log(result)
Example 2: javascript find object by property in array
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
Example 3: find a single element in array of objects javascript
myArray.find(x => x.id === '45').foo;