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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -