1//get random value from array
2var colors = ["red","blue","green","yellow"];
3var randColor = colors[Math.floor(Math.random() * colors.length)];
4
1var myArray = [
2 "Apples",
3 "Bananas",
4 "Pears"
5];
6
7var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
1//Make all arrays have "random" method
2Array.prototype.random = function() {
3 return this[Math.floor(Math.random() * this.length)];
4}
5
6//Call "random" method on an array
7var result = ["Hello", "world"].random();