Skip to content

Function: every()

ts
function every<T>(collection, predicate): boolean;

Checks whether every item in an array or object matches a predicate. 检查数组或对象中的所有元素是否都满足断言。

Type Parameters

Type ParameterDescription
T extends Record<string, unknown> | readonly unknown[]The source collection type / 源集合类型

Parameters

ParameterTypeDescription
collectionTThe source collection / 源集合
predicate(value, key, collection) => booleanThe match predicate / 匹配断言

Returns

boolean

true when all items match / 全部匹配时返回 true

Example

ts
every({ a: 1, b: 2 }, (value) => value > 0)
// => true

Since

1.2.0

Released under the MIT License.