every
The every() method checks whether all elements of an array satisfy a given condition.
Interactive example
Syntax
Classic signature
typescript
function every<
GenericInput extends readonly unknown[]
>(
input: GenericInput,
predicate: (
element: GenericInput[number],
params: ArrayEveryParams<GenericInput>
) => boolean
): booleanCurried signature
typescript
function every<
GenericInput extends readonly unknown[]
>(
predicate: (
element: GenericInput[number],
params: ArrayEveryParams<GenericInput>
) => boolean
): (input: GenericInput) => booleanHelper parameters
typescript
interface ArrayEveryParams<
GenericInputArray extends readonly unknown[]
> {
index: number;
self: GenericInputArray;
}Parameters
input: The array to test.predicate: Predicate function that tests each element. Receives the element, its index, and the whole array.params.index: Position of the current element.params.self: The whole array (useful for comparisons or inspecting a neighbor).
Return value
true if all elements satisfy the condition, false otherwise.
See also
some- Checks whether at least one element satisfies a conditionfind- Finds the first element that satisfies a condition
