1const simpleArray = [3, 5, 7, 15];
2const objectArray = [{ name: 'John' }, { name: 'Emma' }]
3
4console.log( simpleArray.find(e => e === 7) )
5// expected output 7
6
7console.log( simpleArray.find(e => e === 10) )
8// expected output undefined
9
10console.log( objectArray.find(e => e.name === 'John') )
11// expected output { name: 'John' }
1const array1 = [5, 12, 8, 130, 44];
2
3const found = array1.find(element => element > 10);
4
5console.log(found);
6// expected output: 12
1var ages = [3, 10, 18, 20];
2
3function checkAdult(age) {
4 return age >= 18;
5}
6/* find() runs the input function agenst all array components
7 till the function returns a value
8*/
9ages.find(checkAdult);
10
1const myArray = ["sun","moon","earth"];
2const lookingFor = "earth"
3
4console.log(myArray.find(planet => { return planet === lookingFor })
5// expected output: earth