random item from array javascript

JavaScript
//get random value from array
var colors = ["red","blue","green","yellow"];
var randColor = colors[Math.floor(Math.random() * colors.length)];
var colors = ["red","blue","green","yellow"];
var randomColor = colors[Math.floor(Math.random()*colors.length)]; //pluck a random color
var textArray = [
    'song1.ogg',
    'song2.ogg'
];
var randomNumber = Math.floor(Math.random()*textArray.length);const randomElement = array[Math.floor(Math.random() * array.length)];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);function RandomItemFromArray(myArray) {
    return myArray[Math.floor(Math.random() * myArray.length)]
}

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

let fruitSample = RandomItemFromArray(fruit) 
Source

Also in JavaScript: