find();数组
find() 方法返回经过测试(函数内判断)的数组的第一个元素的值。函数
find() 方法为数组中的每一个元素都调用一次函数执行:测试
注意: find() 对于空数组,函数是不会执行的。this
注意: find() 并无改变数组的原始值。spa
[1,2,3,4,5,6].find((n) => n < 5) //找出数组中第一个大于5 的成员 // 6
array.find(function(currentValue, index, arr),thisValue) currentValue : 必需。当前元素 index:可选。当前元素的索引值 arr: 可选。当前元素所属的数组对象 thisValue: 可选。 传递给函数的值通常用 "this" 值。 若是这个参数为空, "undefined" 会传递给 "this" 值
findIndex();code
findIndex() 方法返回传入一个测试条件(函数)符合条件的数组第一个元素位置。对象
findIndex() 方法为数组中的每一个元素都调用一次函数执行:blog
注意: findIndex() 对于空数组,函数是不会执行的。索引
注意: findIndex() 并无改变数组的原始值。io
[3,10,18,19].findIndex((n) => n >= 18) //返回符合条件的值的位置(索引) // 2
array.findIndex(function(currentValue, index, arr),thisValue) currentValue : 必需。当前元素 index:可选。当前元素的索引值 arr: 可选。当前元素所属的数组对象 thisValue: 可选。 传递给函数的值通常用 "this" 值。 若是这个参数为空, "undefined" 会传递给 "this" 值