javascript删除数组里的对象

时间:2023-03-10 02:25:41
javascript删除数组里的对象
Array.prototype.del = function(value) {
//删除数组中指定的元素,返回新数组
function hasValue(array, value) {
for(var i = 0; i < array.length; i++) {
if (value == array[i]) {
return i;
}
}
return -1;
}
var position = hasValue(this, value);
var temp = new Array ;
if(position != -1) {
temp = this.slice(0, position).concat(this.slice(position+1, this.length));
return temp;
}
return this;
}