“Escolha o valor aleatório da matriz” Respostas de código

Escolha String aleatória do JavaScript de Array

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 

Joyous Jackal

Escolha um elemento aleatório de um JavaScript de Array

var myArray = [
  "Apples",
  "Bananas",
  "Pears"
];

var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
Enthusiastic Elephant

Escolha o valor aleatório da matriz

 javascriptCopyvar myArray = ['one', 'two', 'three', 'four', 'five'];
var rand = Math.floor(Math.random()*myArray.length);
var rValue = myArray[rand];
console.log(rValue)
Vivacious Vendace

Respostas semelhantes a “Escolha o valor aleatório da matriz”

Procure respostas de código populares por idioma

Procurar outros idiomas de código