0

How do I get random item from items?

var items = Array(523,3452,334,31,...5346);

29th Aug 2018, 9:19 AM
amber stolck
amber stolck - avatar
4 Réponses
+ 3
Update: This question is copy pasted from here (https://stackoverflow.com/questions/5915096/get-random-item-from-javascript-array) I had put the code into description, it was in the title. I hope there was some actual difficulty and simply wasn't an attempt to get a badge or an upvote. My effort... Basically write a random number generator which returns the array index from 0 to last element in the array. //code below var items =[523, 3452, 334, 31, 5346] items[Math.floor(Math.random() * (items.length))]
29th Aug 2018, 10:23 AM
Lord Krishna
Lord Krishna - avatar
+ 2
It works just the same. If it does not, share your code so it's analyzed.
29th Aug 2018, 11:29 AM
Lord Krishna
Lord Krishna - avatar
0
ok but when my arry is a string not number what i do
29th Aug 2018, 11:24 AM
amber stolck
amber stolck - avatar
0
thank you sir
29th Aug 2018, 11:31 AM
amber stolck
amber stolck - avatar