how to choose a randome item in my array javascript code example
Example 1: Javascript get random item from array
var colors = ["red","blue","green","yellow"];
var randomColor = colors[Math.floor(Math.random()*colors.length)];
Example 2: js get random number from array
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const randomMonth = months[Math.floor(Math.random() * months.length)];
console.log("random month =>", randomMonth);
Example 3: js random string from array
const randomElement = array[Math.floor(Math.random() * array.length)];