Skip to content

Instantly share code, notes, and snippets.

@RinatValiullov
Created January 18, 2018 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RinatValiullov/4e6db5147657ac3244573a4ae4abbca1 to your computer and use it in GitHub Desktop.
Save RinatValiullov/4e6db5147657ac3244573a4ae4abbca1 to your computer and use it in GitHub Desktop.
Return random element of an array
function randEl( array ) {
return array[Math.round(Math.random() * (array.length - 1))]
};
const myArray = [1,2,3,4,5,6,7,8,9];
randEl( myArray ); // random element of an myArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment