javascript get random index from array code example
Example 1: how to get a random element of an array javascript
var foodItems = ["Bannana", "Apple", "Orange"];
var theFood = foodItems[Math.floor(Math.random() * foodItems.length)];
Example 2: javascript how to get a random element from an array
var items = ['Yes', 'No', 'Maybe'];
var item = items[Math.floor(Math.random() * items.length)];
Example 3: get random item from array javascript
const randomElement = array[Math.floor(Math.random() * array.length)];
Example 4: get random entry from array javascript
const rnd = (arr) => { return arr[Math.floor(Math.random() * arr.length)] };