Skip to content

randomItem

Picks a random item from an array.

Usage

ts
import { randomItem } from 'tsu'

randomItem(['ribbit', 'croak', 'peep'])
// eg: 'croak'

Type Definitions

ts
/**
 * @param array - The array.
 * @returns The randomly picked item.
 */
function randomItem<T>(array: readonly T[]): T

Released under the MIT License.