For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/filterAsync.md.

filterAsync es-toolkit

Filters an array using an async predicate function and returns a new array containing only the elements that satisfy the condition.

const filtered = await filterAsync(array, predicate);

Reference

filterAsync(array, predicate, options?)

Use filterAsync to filter an array with async operations like API calls or database queries. Unlike regular filter, it supports async predicate functions and allows you to limit concurrency with the concurrency option.

import { filterAsync } from 'es-toolkit/array';

// Filter for active users by checking their status via API.
const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
const activeUsers = await filterAsync(users, async user => {
  return await checkUserStatus(user.id);
});
// Returns: Array containing only active users

// Limit concurrency to reduce server load.
const numbers = [1, 2, 3, 4, 5];
const evenNumbers = await filterAsync(numbers, async n => await isEvenAsync(n), { concurrency: 2 });
// Only 2 operations run concurrently at most.

The concurrency option helps limit external API calls or manage system resources efficiently. If not specified, all operations run concurrently.

import { filterAsync } from 'es-toolkit/array';

// Execute at most 3 API calls concurrently.
const items = await filterAsync(largeArray, async item => await validateItem(item), { concurrency: 3 });

Parameters

arrayreadonly T[]required

The array to filter.

predicate(item: T, index: number, array: readonly T[]) => Promise<boolean>required

An async function that tests each element. If it returns a truthy value, the element is included in the result.

optionsFilterAsyncOptionsoptional

Options to control concurrency.

  • concurrency (number, optional): Maximum number of concurrent operations. If not specified, all operations run concurrently.

Returns

A promise that resolves to a new array containing only the elements for which the predicate function returned a truthy value.

Promise<T[]>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.