// 先为数组增加remove属性
Array.prototype.remove = function (obj) {
for (var i = 0; i < this.length; i++) {
var temp = this[i];
if (!isNaN(obj)) {
temp = i;
}
if (temp == obj) {
for (var j = i; j < this.length; j++) {
this[j] = this[j + 1];
}
this.length = this.length - 1;
}
}
}
// 使用
var list = [0,1,2,3];
console.log('--->>删除前');
console.log(list);
list.remove(0);
console.log('--->>删除后');
console.log(list);
js数组根据下标删除元素
最新推荐文章于 2024-03-26 22:08:14 发布