用法
-
find() 方法返回通过测试(函数内判断)的数组的第一个元素的值。
-
如果没有符合条件的元素返回 undefined
-
find() 对于空数组,函数是不会执行的。
-
find() 并没有改变数组的原始值。
-
array.find(function(currentValue, index, arr),thisValue),其中currentValue为当前项,index为当前索引,arr为当前数组
实例
let test = [1, 2, 3, 4, 5];
let a = test.find(item => item > 3);
console.log(a); //4
let b = test.find(item => item == 0);
console.log(b); //undefined
本文详细介绍了JavaScript中find()方法的使用,包括其如何返回数组中第一个通过测试的元素值,若无符合条件的元素则返回undefined。文章还提供了具体实例,如查找大于3的首个元素及查找等于0的元素。
431

被折叠的 条评论
为什么被折叠?



