get random value from array in javascript code example
Example 1: javascript get random array value
var colors = ["red","blue","green","yellow"];
var randColor = colors[Math.floor(Math.random() * colors.length)];
Example 2: how to get a random element of an array javascript
var foodItems = ["Bannana", "Apple", "Orange"];
var theFood = foodItems[Math.floor(Math.random() * foodItems.length)];
Example 3: get random element from array js
var item = items[Math.floor(Math.random() * items.length)];
Example 4: how to get a random statement from an array in javascript
let Testing1 = ["put","things","here"]
let Generate = Math.floor((Math.random() * Testing1.length));
console.log(Testing1[Generate])
Example 5: get random elements from array javascript
array.sort(() => Math.random() - Math.random()).slice(0, n)