0 points

Select Random Item from an Array


dashboard

Wed Apr 29 2020 11:38:33 GMT+0000 (UTC)

Posted by @CutePixel #javascript

 var myArray = [
  "Apples",
  "Bananas",
  "Pears"
];

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

If you want to select Random Item from an Array use this code.

https://css-tricks.com/snippets/javascript/select-random-item-array/