.find()
find()
method returns the first element in array that satisfies the passed callback functionIf no value satisfies the testing function, undefined
is returned
const array1 = [5, 12, 8, 130, 44]; const foundElement = array1.find(element => element > 10); console.log(foundElement); // 12
.findIndex()
findIndex()
method returns the index of the first element in the array that satisfies the provided testing function
-1
, indicating no element has passed the testconst array1 = [5, 12, 8, 130, 44]; const isLargeNumber = (element) => element > 13; console.log(array1.findIndex(isLargeNumber); // 3