Answers for "how to get random item from an array"

47

javascript get random array value

//get random value from array
var colors = ["red","blue","green","yellow"];
var randColor = colors[Math.floor(Math.random() * colors.length)];
Posted by: Guest on July-31-2019
0

get random element from array js

var item = items[Math.floor(Math.random() * items.length)];
Posted by: Guest on October-28-2020
-1

get random item from array javascript

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

let  randomItem = items[Math.floor(Math.random() * items.length)];
Posted by: Guest on November-20-2020
-1

how to get random item from an array

//Function to make it easier
Array.prototype.random = function() {
    return this[Math.floor((Math.random() * this.length))];
};

var colors = ["red","blue","green","yellow"];
var randomColor = colors.random();
Posted by: Guest on February-24-2021

Code answers related to "how to get random item from an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language