定义:
返回传入一个测试条件(函数)符合条件的数组第一个元素位置。
为数组中的每个元素都调用一次函数执行:
array.findIndex(function(currentValue, index, arr), thisValue)
1、currentValue
必需。当前元素
2、index
可选。当前元素的索引
3、arr
可选。当前元素所属的数组对象
示例:
var ages = [4, 12, 16, 20];
function checkAge(age) {
return age ==12;
}
ages.findIndex(checkAge);
输出值为1,操作为返回数值为12的索引,即索引1
与indexOf()不同,indexOf()为返回数组中某个指定的元素位置 , findIndex()的查询条件则是一个函数