Answers for "random index from array javascript"

16

javascript how to get a random element from an array

var items = ['Yes', 'No', 'Maybe'];
var item = items[Math.floor(Math.random() * items.length)];
Posted by: Guest on March-19-2020
1

javascript random element from array

const randomItem = items[Math.floor(Math.random() * items.length)];
Posted by: Guest on June-14-2021
1

js get random from array

//Make all arrays have "random" method
Array.prototype.random = function() {
    return this[Math.floor(Math.random() * this.length)];
}

//Call "random" method on an array
var result = ["Hello", "world"].random();
Posted by: Guest on March-27-2021

Code answers related to "random index from array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language