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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM