javascript generate random array of numbers 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 item from array javascript
const randomElement = array[Math.floor(Math.random() * array.length)];
Example 4: how do you make a random array in javascript
const Coins = ["Heads","Tails"]
let Generate = Math.floor((Math.random() * Coins.length));
console.log(Coins[Generate])
Example 5: javascript generate array of random different numbers
var arr = [];
while(arr.length < 8){
var r = Math.floor(Math.random() * 100) + 1;
if(arr.indexOf(r) === -1) arr.push(r);
}
console.log(arr);