“JavaScript mendapatkan nilai array acak” Kode Jawaban

JavaScript mendapatkan nilai array acak

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

JavaScript mendapatkan nilai array acak

const months = ["January", "February", "March", "April", "May", "June"];

const random = Math.floor(Math.random() * months.length);
console.log(random, months[random]);
OHIOLee

JavaScript mendapatkan item acak dari array

var colors = ["red","blue","green","yellow"];
var randomColor = colors[Math.floor(Math.random()*colors.length)]; //pluck a random color
Grepper

Pilih elemen acak dari array javascript

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

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

cara mendapatkan elemen acak dari javascript 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

JavaScript mendapatkan nilai array acak

const array = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
const string = "abcdefghijklmnopqrstuvwxyz";

// random item from Array
console.log(array[Math.floor(Math.random() * array.length)]);

// random Char from String
console.log(string[Math.floor(Math.random() * string.length)]);
MattDESTROYER

Jawaban yang mirip dengan “JavaScript mendapatkan nilai array acak”

Pertanyaan yang mirip dengan “JavaScript mendapatkan nilai array acak”

Lebih banyak jawaban terkait untuk “JavaScript mendapatkan nilai array acak” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya