How to write a function to return a random element from an array in Javascript -


function randomelement(array) {   return array[math.floor(math.random()*array.length)]; } 

got far feel missing something....i'm using const not var , using javascript!

help!

cheers!

i'm such idiot, posted question worked out.....

the code is:

function randomelement(array) {   const findrandom = array[math.floor(math.random()*array.length)];   return findrandom; } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -