This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.
To get a random element from an array, you can use a couple of Math functions to generate a random index and retrieve a value. function random(items) { return items[Math.floor(Math.random() * items.length)] } How it works Math.random() generates a random float between 0 and 1 . The generated float is always less than 1 , so when we multiply it by the length of the array, it's always going to be…
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.