shuffle
Randomly reorders elements of an array using the Fisher-Yates algorithm.
Returns a new array without mutating the original.
null and undefined are treated as empty arrays and return [].
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | null | undefined | The array to shuffle |
Returns
Section titled “Returns”T[] — A new array with the same elements in random order
Examples
Section titled “Examples”Shuffle an array of numbers
Section titled “Shuffle an array of numbers”Returns a new array with the same elements in random order using the Fisher-Yates algorithm.
Original array is not mutated
Section titled “Original array is not mutated”The original array remains unchanged.
