Hello guys, if you want to get a random item from an array in JavaScript, then in this article, you will know that how you can easily select a random value from an array using JavaScript.

Example

You can access every item of an array using its index. For example,you want to get the first element of an array, use array[0],to get the second item use array[1], and so on.

  1. Math.random() method is used to get a random number between 0 to 1 (1 exclusive).
  2. To get the numbers between 0 to array length, multiply the Math.random() value by array length.
  3. The result will be a decimal number. So, round the result to the nearest integer that is equal to or lower than the random value using Math.floor() method.