var arr=[1,2,3,4,5,6,7,8,9];
Array.prototype.remove=function (index) {
var value=this[index];
var list=[];
for (var i=0; i<this.length; i++) {
if (i>=index) {
this[i]=this[i+1];
}
}
this.pop();
return value;
};
Array.prototype.randomList=function () {
var randomList=[];
while (this.length>0) {
var random=Math.floor(Math.random()*this.length);
randomList.push(this.remove(random));
}
return randomList;
}
alert(arr.randomList())
javascript扩展数组删除元素方法和随机排序方法
最新推荐文章于 2024-10-11 17:39:47 发布