Skip to content

draw

Get a random item from a list

155 bytes

Usage

Draw, as in ‘to draw a card from a deck’, is used to get a random item from an array.

import * as
import _
_
from 'radashi'
const
const fish: string[]
fish
= ['marlin', 'bass', 'trout']
import _
_
.
draw<string[]>(array: string[]): string | null
export draw

“Draw” a random item from an array. The item is not removed from the array. Returns null if the array is empty.

@seehttps://radashi.js.org/reference/random/draw

@example

const numbers = [1, 2, 3]
draw(numbers)
// => 2
numbers
// => [1, 2, 3]

@version12.1.0

draw
(
const fish: string[]
fish
) // => a random fish