some
The some() method checks whether at least one element of an array satisfies a given condition.
Interactive example
Syntax
Classic signature
typescript
function some<
GenericInput extends readonly unknown[]
>(
input: GenericInput,
predicate: (
element: GenericInput[number],
params: ArraySomeParams<GenericInput>
) => boolean
): booleanCurried signature
typescript
function some<
GenericInput extends readonly unknown[]
>(
predicate: (
element: GenericInput[number],
params: ArraySomeParams<GenericInput>
) => boolean
): (array: GenericInput) => booleanHelper parameters
typescript
interface ArraySomeParams<
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 to compare the position or access a neighbor).
Return value
true if at least one element satisfies the condition, false otherwise.
See also
every- Checks whether all elements satisfy a conditionfind- Finds the first element that satisfies a condition
