ramdom element from array code example
Example 1: get random element from array js
var item = items[Math.floor(Math.random() * items.length)];
Example 2: js get random from array
//Make all arrays have "random" method
Array.prototype.random = function() {
return this[Math.floor(Math.random() * this.length)];
}
//Call "random" method on an array
var result = ["Hello", "world"].random();