0
How do I get random item from items?
var items = Array(523,3452,334,31,...5346);
4 Antworten
+ 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))]
+ 2
It works just the same. If it does not, share your code so it's analyzed.
0
ok but when my arry is a string not number what i do
0
thank you sir