1const inventory = [
2 {name: 'apples', quantity: 2},
3 {name: 'cherries', quantity: 8}
4 {name: 'bananas', quantity: 0},
5 {name: 'cherries', quantity: 5}
6 {name: 'cherries', quantity: 15}
7
8];
9
10const result = inventory.find( ({ name }) => name === 'cherries' );
11
12console.log(result) // { name: 'cherries', quantity: 5 }
1const array1 = [5, 12, 8, 130, 44];
2
3const found = array1.find(element => element > 10);
4
5console.log(found);
6// expected output: 12
1const array1 = [5, 12, 8, 130, 44];
2
3const found = array1.find(element => element > 10);
4
5console.log(found);
6// expected output: 12
7
1const inventory = [
2 {name: 'apples', quantity: 2},
3 {name: 'bananas', quantity: 0},
4 {name: 'cherries', quantity: 5}
5];
6
7function isCherries(fruit) {
8 return fruit.name === 'cherries';
9}
10
11console.log(inventory.find(isCherries));
12// { name: 'cherries', quantity: 5 }