Search code examples
javascriptarraysrandom

Get a random item from a JavaScript array


var items = Array(523, 3452, 334, 31, ..., 5346);

How do I get random item from items?


Solution

  • var item = items[Math.floor(Math.random()*items.length)];