当前位置:网站首页>JS interview questions - arrow function, find and filter some and every

JS interview questions - arrow function, find and filter some and every

2022-06-11 11:24:00 kilito_ 01

 Insert picture description here
find and filter The difference between

var a = [1,2,3,4,5,6,7]

a.find(item =>{ retuen item > 2})
find What will be returned is the specific value And only match the first result

a.filter(item =>{ retuen item > 2})
Will return all greater than 2 The data of
filter Will return a new array , The original array will not change It will filter out all qualified data

some and every The difference between

They all put back Boolean values
a.some(item =>{ retuen item > 2})
some Yes, as long as there is a value that meets the condition It will return true

a.every (item =>{ retuen item > 2})
every All values must meet the conditions Will return true

原网站

版权声明
本文为[kilito_ 01]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111108241563.html