JS getting a random element from an array with gaps in it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

JS getting a random element from an array with gaps in it

So I'm trying to lay out the framework for card game, I've made an array with a few card elements in it, but their position in the array is not linear. I'll be giving them all 6 digit numbers in the array index for organization later. for example one would be 123001 and the next could 104752. I've found a lot of people saying use math.floor( math.ran() * array.length) but this will not work here as there are large empty gaps in my array and I would like to keep it that way if possible. Thank you for any and all responses :)

14th Jul 2018, 5:08 PM
Colin
0 Answers