sample es-toolkit
Returns a randomly selected element from an array.
Usage
sample(arr)
Use sample when you want to randomly select one element from an array. It's useful for selecting random items in games, randomly fetching test data, or conducting draws.
It can also be used with various types of arrays.
Parameters
arrreadonly T[]required
The array from which to randomly select an element.
Returns
A randomly selected element from the array.
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.