Shuffle

Randomizes the order of elements in an array using the Fisher-Yates algorithm.

CategoryArrays
AuthorPol Gubau
Since1.0.0
Last Updated2025-03-15
TypeSync
CompatibilityUniversal

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

NameTypeDefaultRequiredDescription
arrT[]nullYesThe 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

Related