xxxxxxxxxx
// List your array items
let Testing1 = ["put","things","here"]
let Generate = Math.floor((Math.random() * Testing1.length)); // Generates a number of the array.
// logs the result
console.log(Testing1[Generate])
xxxxxxxxxx
//get random value from array
var colors = ["red","blue","green","yellow"];
var randColor = colors[Math.floor(Math.random() * colors.length)];
xxxxxxxxxx
var colors = ["red","blue","green","yellow"];
var randomColor = colors[Math.floor(Math.random()*colors.length)]; //pluck a random color
xxxxxxxxxx
var items = ['Yes', 'No', 'Maybe'];
var item = items[Math.floor(Math.random() * items.length)];
xxxxxxxxxx
var foodItems = ["Bannana", "Apple", "Orange"];
var theFood = foodItems[Math.floor(Math.random() * foodItems.length)];
/* Will pick a random number from the length of the array and will go to the
corosponding number in the array E.G: 0 = Bannana */
xxxxxxxxxx
const array = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
const string = "abcdefghijklmnopqrstuvwxyz";
// `Math.floor` can be replaced with `~~`
// random item from Array
console.log(array[Math.floor(Math.random() * array.length)]);
// random Char from String
console.log(string[Math.floor(Math.random() * string.length)]);
xxxxxxxxxx
const months = ["January", "February", "March", "April", "May", "June"];
const random = Math.floor(Math.random() * months.length);
console.log(random, months[random]);
xxxxxxxxxx
const randomElement = array[Math.floor(Math.random() * array.length)];