Skip to content

Instantly share code, notes, and snippets.

@kdev
Created August 13, 2019 19:45
Show Gist options
  • Save kdev/a62efbe93f48831462f368cc011a27a9 to your computer and use it in GitHub Desktop.
Save kdev/a62efbe93f48831462f368cc011a27a9 to your computer and use it in GitHub Desktop.
// define a Array
let array = ["String 1", "STRING 2", "String 3"];
// defining a new function named getRandomIndex
let getRandomIndex = array => {
// get a random number between 0 and 1 and * by the array lenght
let rand = Math.floor(Math.random() * array.length);
// let the index is the random number from above
let randIndex = array[rand];
// return the array item
return randIndex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment