Skip to content

Latest commit

 

History

History

findIndex

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

介绍

findIndex(),接收回调函数一个,过滤出满足条件的第一个元素的索引,没找到则返回 -1。此方法不改变原数组。

MDN 参考

语法

arr.findIndex(callback(element[, index[, array]])[, thisArg])

参数

callback
用以测试数组元素,满足则返回该元素索引,并结束遍历。其参数有三:
element
当前元素
index(可选)
当前索引
array(可选)
调用 find 的数组
thisArg(可选)
callback 所绑定的 this

返回值

返回满足条件的第一个元素索引,否则返回 -1