How do I randomly pick a value from a js array

  • 2020-03-30 03:21:47
  • OfStack

 
<html> 
<boby> 
</body> 

<script language="javascript"> 
window.onload = function(){ 
var arr = [" The sun is bright, the parents are generous, the gentleman is big, the small popularity is big "," Success is the play of the advantages, failure is the accumulation of shortcomings "," Don't underestimate yourself, because people have unlimited possibilities ", 
" Good words, good intentions, good deeds "," To forgive is to be kind to oneself "," Palm down is to help, palm up is to ask; Help others for pleasure, ask for pain " 
]; 

var index = Math.floor((Math.random()*arr.length)); 
alert(arr[index]); 

} 
</script> 
</html> 

Related articles: