Answers for "get random number from list js"

1

how to get a randome element from a list in javascript

let numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let randomElem = numList[Math.floor(Math.random() * numList.length)];
console.log(randomElem);
Posted by: Guest on March-30-2021
8

javascript math.random from list

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

var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
Posted by: Guest on April-19-2020

Code answers related to "get random number from list js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language