I have an array that has sequential array keys and I need to randomly select one of the keys... what's the best way to do that?
Math.random() will generate a number between 0 and 1.
var key = Math.floor(Math.random() * arr.length);
Have a look at JavaScript random() Method and Generating a random number in JavaScript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With