JS - every()和some() 判断一个数组对象中的所有数据或某个值都满足条件

时间:2020-07-15 01:39:51   收藏:0   阅读:469

every()和some() 判断一个数组对象中的所有数据或某个值都满足条件

every() 只要有一个不符合条件就为 false (一假即假)
some() 只要有一个符合条件就位 true (一真即真)
 
var arr = [66, 34, 643, 774, 64, 834 ];
console.log( arr.every((a)=> a>=100) ) // false
console.log( arr.some((a)=> a>=40 ) ) // true

var arrObj = [
    { status:0, id:1 },
    { status:1, id:2 },
    { status:0, id:3 },
]
console.log( arrObj.every( (val) => val.status===0) );// false
console.log( arrObj.some( (val) => val.id===2) );// true

 

原文:https://www.cnblogs.com/sanyekui/p/13302371.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!