Array.prototype.remove = function(dx) {
if(isNaN(dx) || dx > this.length) {
return false;
}
for(var i = 0, n = 0; i < this.length; i++) {
if(this[i] != this[dx]) {
this[n++] = this[i]
}
}
this.length -= 1
}
var a = [1, 2, 3, 4, 5]; //目标数组
a.remove(4); //删除目标数组的下标
console.log(a)
if(isNaN(dx) || dx > this.length) {
return false;
}
for(var i = 0, n = 0; i < this.length; i++) {
if(this[i] != this[dx]) {
this[n++] = this[i]
}
}
this.length -= 1
}
var a = [1, 2, 3, 4, 5]; //目标数组
a.remove(4); //删除目标数组的下标
console.log(a)
版权声明:本文为qq_41593072原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。