js find的用法_find方法python
未分类
2023-01-17
js find的用法_find方法python先看下面代码lettest=[1,2,3,4,5];leta=test.find(item=>item>3);console.log(a);//4letb=test.find(item=>item==0);console.log(b);//undefined总结:
先看下面代码, 理解一下, 其实非常的简单.
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
只听到从架构师办公室传来架构君的声音:
乡泪客中尽,孤帆天际看。有谁来对上联或下联?
乡泪客中尽,孤帆天际看。有谁来对上联或下联?
总结:
1.find() 方法用于查找数组中符合条件的第一个元素,如果没有符合条件的元素,则返回 undefined ;
2.find() 对于空数组, 函数是不会执行的.; 不会改变数组的原始值
此代码由Java架构师必看网-架构君整理array.find(function(currentValue,index,arr),thisValue)
currentValue => 指当前的项
index => 指当前索引
arr => 指当前的数组