Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #random #array
ADD COMMENT
Topic
Name
4+5 =