Skip to main content

every()

Try it

every() 方法测试一个数组内的所有元素是否都能通过某个指定函数的测试。它返回一个布尔值。

const isBelowThreshold = (currentValue) => currentValue < 40;

const array1 = [1, 30, 39, 29, 10, 13];

console.log(array1.every(isBelowThreshold));
// expected output: true

语法

返回值

如果回调函数的每一次返回都为 truthy 值,返回 true,否则返回 false。