How to get a random option form the array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to get a random option form the array

14th Jun 2018, 7:39 AM
Aditya ekbote
Aditya ekbote - avatar
2 Answers
+ 2
var rnd= Math.floor(Math.random()*number) arr[rnd]
14th Jun 2018, 12:25 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
0
Define a random number based on the size of your array and then state: array.get(randomnumber)
14th Jun 2018, 7:42 AM
***
*** - avatar