Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript select random element from array

let fruits = ["Apple", "Banana", "Mango", "Orange"]; // array
let index = Math.floor(Math.random() * fruits.length); // random index
console.log(fruits[index]); // result
Source by css-tricks.com #
 
PREVIOUS NEXT
Tagged: #javascript #select #random #element #array
ADD COMMENT
Topic
Name
1+9 =