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

# flatten (Functional Programming) es-toolkit

Creates a function that flattens nested arrays to a given depth. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, flatten(depth));
```

::: info

Prefer the original es-toolkit [`flatten`](https://massaman.dev/reference/array/flatten.md) in ordinary code. Use this `fp` variant when composing transformations with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

:::

## Usage

`flatten` flattens the piped array up to `depth`. When `depth` is omitted, it flattens one level. It is lazy-capable for one-level flattening inside [`pipe`](https://massaman.dev/reference/fp/pipe.md).

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

pipe([[1], [2, 3], [4]], flatten()); // => [1, 2, 3, 4]
```

#### Parameters


depthnumber, optionalrequired

The depth to flatten. Defaults to `1`.

#### Returns

A function that maps a nested array to a flattened array.

```typescript
(array: readonly T[]) => Array<FlatArray<T[], D>>
```


Source: es-toolkit

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