For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/fp/intersection.md.

intersection (Functional Programming) es-toolkit

Creates a function that keeps values found in another array. Use it with pipe.

const result = pipe(array, intersection(secondArray));
Info

Prefer the original es-toolkit intersection in ordinary code. Use this fp variant when composing transformations with pipe.

Usage

intersection keeps values from the piped array that are also present in secondArray. It preserves the order of the piped array.

import { intersection, pipe } from 'es-toolkit/fp';

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

Parameters

secondArrayreadonly T[]required

The array containing values to keep.

Returns

A function that maps a readonly T[] to values also found in secondArray.

(array: readonly T[]) => T[]
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.