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

# differenceBy (Functional Programming) es-toolkit

Creates a function that excludes values by a mapped key. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, differenceBy(secondArray, mapper));
```

::: info

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

:::

## Usage

`differenceBy` compares the values returned by `mapper`. Values from the piped array are kept when their mapped key does not appear in `secondArray`.

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

pipe(
  [{ id: 1 }, { id: 2 }],
  differenceBy([2], value => (typeof value === 'number' ? value : value.id))
); // => [{ id: 1 }]
```

#### Parameters


secondArrayreadonly U[]required

The array containing values whose mapped keys should be excluded.


mapper(item: T | U) => unknownrequired

The function that returns the comparison key.

#### Returns

A function that maps a `readonly T[]` to values whose keys are not found in `secondArray`.

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


Source: es-toolkit

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