“como obter item aleatório de uma matriz” Respostas de código

JavaScript Obtenha valor de matriz aleatória

//get random value from array
var colors = ["red","blue","green","yellow"];
var randColor = colors[Math.floor(Math.random() * colors.length)];
Grepper

Como obter um elemento aleatório de um JavaScript de Array

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 */
Your moms hornyness

Obtenha elemento aleatório do Array JS

var item = items[Math.floor(Math.random() * items.length)];
Worried Willet

Obtenha um item aleatório do JavaScript de Array

let items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119];

let  randomItem = items[Math.floor(Math.random() * items.length)];
Creepy Gábor

Obtenha item aleatório na matriz

function getRandomNumberElement(items: number[]): number {
    let randomIndex = Math.floor(Math.random() * items.length);
    return items[randomIndex];
}
Code language: TypeScript (typescript)
Grumpy Gerbil

Respostas semelhantes a “como obter item aleatório de uma matriz”

Perguntas semelhantes a “como obter item aleatório de uma matriz”

Procure respostas de código populares por idioma

Procurar outros idiomas de código