1var groceries = [
2'milk',
3'coriander',
4'cucumber',
5'eggplant'
6]
7let mygroceries = groceries[Math.floor(Math.random() * groceries.length)]
8console.log(mygroceries)//This gives you any string from groceries
9
10
1var myArray = [
2 "Apples",
3 "Bananas",
4 "Pears"
5];
6
7var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
1 javascriptCopyvar myArray = ['one', 'two', 'three', 'four', 'five'];
2var rand = Math.floor(Math.random()*myArray.length);
3var rValue = myArray[rand];
4console.log(rValue)
5
1const months = ["January", "February", "March", "April", "May", "June", "July"];
2
3const random = Math.floor(Math.random() * months.length);
4console.log(random, months[random]);
1//Function to make it easier
2Array.prototype.random = function() {
3 return this[Math.floor((Math.random() * this.length))];
4};
5
6var colors = ["red","blue","green","yellow"];
7var randomColor = colors.random();