get random index value from an array

PHOTO EMBED

Sun Mar 19 2023 07:48:30 GMT+0000 (Coordinated Universal Time)

Saved by @davidmchale #index #random

const names = ['david', 'gary', 'shaun', 'stephen'];


function getRandomIndex(array){
  const index = Math.floor(Math.random() * array.length);
  let randomNumber = array[index];
  return randomNumber;
}

getRandomIndex(names)
content_copyCOPY