Select Random Item from an Array

Avatar of Chris Coyier
Chris Coyier on
var myArray = [
  "Apples",
  "Bananas",
  "Pears"
];

var randomItem = myArray[Math.floor(Math.random()*myArray.length)];

See the Pen gLJPZv by Chris Coyier (@chriscoyier) on CodePen.