Answers for "pick random value in javascript"

8

pick a random element from an array javascript

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

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

get random elements from array javascript

array.sort(() => Math.random() - Math.random()).slice(0, n)
Posted by: Guest on September-10-2020

Code answers related to "pick random value in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language