Shuffle
Randomizes the order of elements in an array using the Fisher-Yates algorithm.
| Category | Arrays |
| Author | Pol Gubau |
| Since | 1.0.0 |
| Last Updated | 2025-03-15 |
| Type | Sync |
| Compatibility | Universal |
Example
Input
shuffle([1, 2, 3, 4, 5])Output:
[3, 1, 4, 5, 2]
Return
A new array with its elements shuffled in random order.
Type: array
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| arr | T[] | null | Yes | The array to shuffle. |
Notes
The function uses the Fisher-Yates algorithm to shuffle the elements in place. It does not mutate the original array.
Tags
- array
- shuffle
- random