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

# map (Functional Programming) es-toolkit

Creates a function that transforms every element of an array, equivalent to `Array.prototype.map`. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, map(callbackfn));
```

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

`map` builds a new array by calling `callbackfn` on each element. It is **lazy-capable**: inside a [`pipe`](https://massaman.dev/reference/fp/pipe.md) it is fused with adjacent lazy operations, so a trailing `take` can stop the work early.

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

// Transform each element.
pipe(
  [1, 2, 3],
  map(x => x * 2)
); // => [2, 4, 6]

// The index is available as the second argument.
pipe(
  [10, 20, 30],
  map((value, index) => value + index)
); // => [10, 21, 32]

// The element type can change.
pipe(
  [1, 2, 3],
  map(x => `#${x}`)
); // => ['#1', '#2', '#3']
```

#### Parameters


callbackfn(value: T, index: number) => Urequired

A function called for each element; its return value becomes the corresponding element of the output array.

#### Returns

A function that maps a `readonly T[]` to a new `U[]`.

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


Source: es-toolkit

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