HomeToolsAbout

find

.find()

  • The find() method returns the first element in array that satisfies the passed callback function

If 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

  • Otherwise, it returns -1, indicating no element has passed the test
const array1 = [5, 12, 8, 130, 44]; const isLargeNumber = (element) => element > 13; console.log(array1.findIndex(isLargeNumber); // 3
AboutContact