Get Random Value From Array in JS

function getRandomValue(arrValue, options = {  }) {
    // Example: let vlaueArray = ["...", "..."]
    try {
      let ranValue = Math.floor(Math.random() * arrValue.length);

      if (arrValue && Array.isArray(arrValue) === true)
        return arrValue[ranValue];
    } catch (err) {
      return err;
    }
  }

Leave a comment