randomn array js code example
Example 1: random item from array javascript
function RandomItemFromArray(myArray) {
return myArray[Math.floor(Math.random() * myArray.length)]
}
var fruit = [ "Apples", "Bananas", "Pears", ];
let fruitSample = RandomItemFromArray(fruit)
Example 2: random array javascript
const months = ["January", "February", "March", "April", "May", "June", "July"];
const random = Math.floor(Math.random() * months.length);
console.log(random, months[random]);