您的位置:首页 > Web前端 > JavaScript

js为Array添加打乱元素顺序的函数shuffle()

2016-07-14 15:32 573 查看
var data = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
if (!Array.prototype.shuffle) {
Array.prototype.shuffle = function() {
for(var j, x, i = this.length;
j = parseInt(Math.random() * i),
this[i] = this[j],
this[j] = x);
return this;
};
}
alert(data.shuffle());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript