get random item of arrya code example
Example 1: get random element from array js
var item = items[Math.floor(Math.random() * items.length)];
Example 2: how to get random item from an array
//Function to make it easier
Array.prototype.random = function() {
return this[Math.floor((Math.random() * this.length))];
};
var colors = ["red","blue","green","yellow"];
var randomColor = colors.random();