Function randomChoice

  • Returns a random element from the array or undefined if the array is empty.

    Type Parameters

    • T

    Parameters

    • array: readonly T[]

    Returns T | undefined

    Example

    randomChoice([1, 2, 3, 4, 5])
    // 2