ts-utils
    Preparing search index...

    Function randomItem

    • Get a random item from the given array.

      Type Parameters

      • Item

        Type of the array elements.

      Parameters

      • array: Item[]

        The array to retrieve a random item from.

      Returns undefined | Item

      A random item from the array.

      randomItem(['a', 'b', 'c', 'd', 'e']);
      // => 'c'
      randomItem(['a', 'b', 'c', 'd', 'e']);
      // => 'e'
      randomItem([]);
      // => undefined