Skip to content

shuffle

The shuffle function randomly shuffles the elements of an array.

Syntax

typescript
shuffle<T>(array: T[]): T[];

Parameters

NameTypeDescription
arrayT[]Source array

Returns

TypeDescription
T[]New shuffled array

Examples

typescript
shuffle([1, 2, 3, 4]); // => [3, 1, 4, 2] (example)

Notes

  • The original array may be modified.
  • Useful for draws and list randomization.

References

Released under the MIT License.