javascript Array.some()和Array.every()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Array.some()和Array.every()相关的知识,希望对你有一定的参考价值。

//Array.some() - will check the data in an array if some meet what you are looking for
const ages = [32, 15, 19, 12];

// is there at least one adult in the group?
const adultPresent = ages.some(age => age >= 18);
console.log(adultPresent);


//Array.every() will check the data in an array if all of the items meet what you are looking for
// is everyone old enough to drink?
const allOldEnough = ages.every(age => age >= 19);
console.log(allOldEnough);

以上是关于javascript Array.some()和Array.every()的主要内容,如果未能解决你的问题,请参考以下文章

在javascript中嵌套array.some()

数组的方法 Array.map();Array.every()和Array.some();数组的indexof();

Javascript-多个数组是否有一样值

Typescript - 无法在 Array.some [重复] 中访问“this”

array.some() 方法兼容ie8

JS ECMAScript 5中的every 和 some方法进行逻辑判断