find() && findIndex()

findIndex() 

The first element of the test function returns an array of offers to meet the index . Otherwise, it returns -1.

const array1 = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
// expected output: 3

find() 

The first element of the test function returns an array provided satisfied. Otherwise returned  undefined.

const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
// expected output: 12

  

Guess you like

Origin www.cnblogs.com/blogZhao/p/12560445.html