pick random string from array javascript
var groceries = [
'milk',
'coriander',
'cucumber',
'eggplant'
]
let mygroceries = groceries[Math.floor(Math.random() * groceries.length)]
console.log(mygroceries)//This gives you any string from groceries
pick random string from array javascript
var groceries = [
'milk',
'coriander',
'cucumber',
'eggplant'
]
let mygroceries = groceries[Math.floor(Math.random() * groceries.length)]
console.log(mygroceries)//This gives you any string from groceries
pick a random element from an array javascript
var myArray = [
"Apples",
"Bananas",
"Pears"
];
var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
Pick Random Value From Array
javascriptCopyvar myArray = ['one', 'two', 'three', 'four', 'five'];
var rand = Math.floor(Math.random()*myArray.length);
var rValue = myArray[rand];
console.log(rValue)
pick random from array
const months = ["January", "February", "March", "April", "May", "June", "July"];
const random = Math.floor(Math.random() * months.length);
console.log(random, months[random]);
how to get random item from an array
//Function to make it easier
Array.prototype.random = function() {
return this[Math.floor((Math.random() * this.length))];
};
var colors = ["red","blue","green","yellow"];
var randomColor = colors.random();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us