js数组中随机取值

从数组中随机取值

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
</head>
<body>
</body>
<script>
  window.onload = function() {
    var arr = ["009", "002", "006", "003", "001", "005"];
    var index = Math.floor((Math.random()*arr.length));
    console.log(arr[index]);
  }
</script>
</html>

 

posted @ 2016-12-27 17:09  jmwei  阅读(1917)  评论(0编辑  收藏  举报