JS查找数组中元素index

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

原文地址:https://www.cnblogs.com/j2ee-web-01/p/15252410.html