pick a random number in an array code example
Example 1: pick a random element from an array javascript
var myArray = [
"Apples",
"Bananas",
"Pears"
];
var randomItem = myArray[Math.floor(Math.random()*myArray.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();