How to get random value from array in JavaScript

1 Answer

0 votes
var arr = ["javascript", "c", "python", "php", "c++", "java"];

var s = arr[(Math.floor(Math.random() * (arr.length)))]

console.log(s); 

  
    
    
/*
run:
    
"php"
    
*/

 



answered Feb 15, 2021 by avibootz
...