+ 1

Pick a random item

How do I pick a random item from an array in JavaScript?

14th Jan 2017, 12:23 AM
freakshow
freakshow - avatar
2 ответов
+ 2
var arr=[]; /* set values to 'arr' array */ var c=arr.length-1; var i=Math.round(c*Math.random()) document.write(arr[i]);
14th Jan 2017, 12:37 AM
visph
visph - avatar
+ 1
thanks
14th Jan 2017, 9:48 AM
freakshow
freakshow - avatar