• Get a random value of an Array

    Type Parameters

    • Arr extends any[]

    Parameters

    Returns Arr[number] | undefined

    Example

    import { array } from "@rjweb/utils"

    const arr = ['A', 'B', 'C', 'D', 'E']

    array.random(arr, 2) // 'C'
    array.random(arr, 4) // 'A'

    Since

    1.9.1

    Supports

    nodejs, browser