“JS 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

JavaScript Cara Mendapatkan Elemen Acak dari Array

var items = ['Yes', 'No', 'Maybe'];
var item = items[Math.floor(Math.random() * items.length)];
Helpless Hornet

JS array acak

var demo = document.getElementById("demo");
var fruits = [
"Apple",
"Orange",
"Mango",
"Grapes",
"Banana",
];

demo.innerHTML = fruits[Math.floor(Math.random() * fruits.length)];
RashidYT

Jawaban yang mirip dengan “JS array acak”

Pertanyaan yang mirip dengan “JS array acak”

Lebih banyak jawaban terkait untuk “JS array acak” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya