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

来源:互联网 发布:至此终年网络番外3 编辑:程序博客网 时间:2024/05/05 12:18
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());
0 0