@bytebury/sauce - v2.2.0
    Preparing search index...

    Function sample

    • Pick a random item from an array.

      Type Parameters

      • T

      Parameters

      Returns undefined | T

      If you pass an empty list, then this function will return undefined.

      const myList = [1, 2, 3, 4];
      const randomItem = sample(myList);

      console.log(randomItem); // could be 1, 2, 3, or 4
      console.log(sample([])); // undefined