> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# mapAsync es-toolkit

Transforms each element in an array using an async function and returns a new array.

```typescript
const transformed = await mapAsync(array, callback);
```

## Reference

### `mapAsync(array, callback, options?)`

Use `mapAsync` to perform async transformation operations for each element in an array. It's useful when you need to process each element asynchronously, such as API calls or database queries.

```typescript
import { mapAsync } from 'es-toolkit/array';

// Fetch detailed information for each user.
const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
const userDetails = await mapAsync(users, async user => {
  return await fetchUserDetails(user.id);
});
// Returns: [{ id: 1, name: '...' }, { id: 2, name: '...' }, { id: 3, name: '...' }]

// Limit concurrency.
const numbers = [1, 2, 3, 4, 5];
const results = await mapAsync(numbers, async n => await slowOperation(n), { concurrency: 2 });
// Only 2 operations run concurrently at most.
```

The `concurrency` option allows you to limit concurrent executions to control server load or respect API rate limits. If not specified, all operations run concurrently.

```typescript
import { mapAsync } from 'es-toolkit/array';

// Transform a large number of images, limiting concurrent processing to consider server load.
const imageUrls = [...]; // Many image URLs
const processedImages = await mapAsync(
  imageUrls,
  async (url) => await processImage(url),
  { concurrency: 5 }
);
// Only 5 images are processed at a time at most.
```

#### Parameters


arrayreadonly T[]required

The array to transform.


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

An async function that transforms each element.


optionsMapAsyncOptionsoptional

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 of transformed values.

```typescript
Promise<R[]>
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/array/mapAsync.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
