📌  相关文章
📜  随机访问完整数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:04.794000             🧑  作者: Mango

代码示例1
Array.prototype.shuffle = function(){
  var i = this.length,
      j,
    tmp;
  while (i > 1) {
    j = Math.floor(Math.random()*i--);
    tmp = this[i];
    this[i] = this[j];
    this[j] = tmp;
  }
  return this;
};

var arr = [1,2,3,4,5].shuffle();
for(var i = 0; i < arr.length; i++) console.log(arr[i]);