> 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.

# reduceAsync es-toolkit

Reduces an array to a single value using an async reducer function.

```typescript
const result = await reduceAsync(array, reducer, initialValue);
```

## Reference

### `reduceAsync(array, reducer, initialValue)`

Use `reduceAsync` to reduce an array to a single value by processing each element sequentially. The reducer function is applied sequentially to each element from left to right, passing the accumulated result from one call to the next.

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

// Fetch async values for each number and sum them.
const numbers = [1, 2, 3, 4, 5];
const sum = await reduceAsync(numbers, async (acc, n) => acc + (await fetchValue(n)), 0);
// Returns: Sum of all fetched values

// Transform array to object.
const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
const userMap = await reduceAsync(
  users,
  async (acc, user) => {
    const details = await fetchUserDetails(user.id);
    acc[user.id] = details;
    return acc;
  },
  {} as Record<number, any>
);
// Returns: { 1: {...}, 2: {...}, 3: {...} }
```

Unlike other async array methods, `reduceAsync` must process elements sequentially and does not support concurrent execution, because the result from the previous step is needed for the next step.

#### Parameters


arrayreadonly T[]required

The array to reduce.


reducer(accumulator: U, currentValue: T, currentIndex: number, array: readonly T[]) => Promise<U>required

An async function that processes each element. It receives the accumulated value and current value, and returns the new accumulated value.


initialValueUrequired

The initial value of the accumulator.

#### Returns

A promise that resolves to the final accumulated value.

```typescript
Promise<U>
```

***

### `reduceAsync(array, reducer)`

When reducing an array without an initial value, the first element is used as the initial value and the reducer function is applied starting from the second element.

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

// Calculate sum without initial value.
const numbers = [1, 2, 3, 4, 5];
const sum = await reduceAsync(numbers, async (acc, n) => acc + n);
// Returns: 15 (1 + 2 + 3 + 4 + 5)

// Empty array returns undefined.
const emptyArray: number[] = [];
const result = await reduceAsync(emptyArray, async (acc, n) => acc + n);
// Returns: undefined
```

Calling `reduceAsync` on an empty array without an initial value returns `undefined`.

#### Parameters


arrayreadonly T[]required

The array to reduce.


reducer(accumulator: T, currentValue: T, currentIndex: number, array: readonly T[]) => Promise<T>required

An async function that processes each element. It receives the accumulated value and current value, and returns the new accumulated value.

#### Returns

A promise that resolves to the final accumulated value. Returns `undefined` if the array is empty.

```typescript
Promise<T | undefined>
```


Source: es-toolkit

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