1let arr = [
2 { name:"string 1", value:"this", other: "that" },
3 { name:"string 2", value:"this", other: "that" }
4];
5
6let obj = arr.find(o => o.name === 'string 1');
7
8console.log(obj);
1// To find a specific object in an array of objects
2myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
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 }
1//The find() method returns the value of the first element in the provided array that satisfies the provided testing function.
2const array1 = [5, 12, 8, 130, 44];
3
4const found = array1.find(element => element > 10);
5
6console.log(found);
7// expected output: 12