Skip to main content

filter

Functions

filter()

filter<T>(arrayOrPromise, callbackfn): Promise<T[]>

Creates a new array with all elements that pass the test implemented by the provided function.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
arrayOrPromiseT[] | Promise<T[]>The array or Promise of an array to iterate over.
callbackfn(value, index, array) => boolean | Promise<boolean>A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.

Returns

Promise<T[]>

A Promise that resolves with a new array with the elements that pass the test.

Example

const array = [1, 30, 39, 29, 10, 13];
const result = await filter(array, (value) => value < 30);
console.log(result); // Output: [1, 29, 10, 13]

Defined in

src/filter/index.ts:17