findIndex()方法返回数组中满足提供的测试函数的第一个元素的索引。若没有找到对应元素则返回-1。

 

值类型:   

const array1 = [5, 12, 8, 130, 44];

const isLargeNumber = (element) => element == 12;

console.log(array1.findIndex(isLargeNumber));

 

数组对象:   var index = DiaryNoList.findIndex((value) => value.diaryno == this.info.diaryno);

 

 

find()

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2021-12-26
  • 2022-01-22
  • 2021-12-26
  • 2021-12-26
  • 2022-12-23
  • 2021-12-26
  • 2021-10-15
相关资源
相似解决方案