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/shuffle.md.

shuffle (Functional Programming) es-toolkit

Creates a function that returns a shuffled copy of an array. Use it with pipe.

const result = pipe(array, shuffle());
Info

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

Usage

shuffle returns a new array containing the same values as the piped array in random order. It does not mutate the input array.

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

const values = pipe([1, 2, 3], shuffle());
// values contains 1, 2, and 3 in random order.

Parameters

This function takes no arguments; call it as shuffle().

Returns

A function that maps a readonly T[] to a shuffled copy.

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