Answers for "give random array value"

0

define function to get random value from array

const randomValue = (list) => {
    return list[Math.floor(Math.random() * list.length)];
};
Posted by: Guest on January-30-2022
-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 "Javascript"

Browse Popular Code Answers by Language