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

# forEach (Functional Programming) es-toolkit

Creates a function that runs a callback for each value and returns the input array. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, forEach(callback));
```

::: info

This helper is specific to `es-toolkit/fp`. Use it when you want this operation as part of a [`pipe`](https://massaman.dev/reference/fp/pipe.md) pipeline.

:::

## Usage

`forEach` is useful as a side-effect step in a pipeline. It calls `callback` for each value and passes the original array through. Inside [`pipe`](https://massaman.dev/reference/fp/pipe.md), it is lazy-capable when adjacent lazy operations can stop early.

```typescript
import { forEach, pipe } from 'es-toolkit/fp';

const values: number[] = [];

pipe(
  [1, 2, 3],
  forEach(value => values.push(value))
); // => [1, 2, 3]
values; // => [1, 2, 3]
```

#### Parameters


callback(value: T, index: number) => voidrequired

The function to run for each value.

#### Returns

A function that returns the same array after running the callback.

```typescript
(array: readonly T[]) => readonly T[]
```


Source: es-toolkit

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