实例如下:
复制代码 代码如下:
Array.prototype.deletevalue = function(value){
var i = 0;
for(i in this){
if(this[i] == value) break;
}
return this.slice(0, i).concat(this.slice(parseInt(i, 10) + 1));
}
//示例
var test = new Array(1,5,3,4,2);
//输出5
console.log(test.length);
//删除值为4的元素
test = test.deletevalue(4);
//输出[1, 5, 3, 2]
console.log(test);
//输出4
console.log(test.length);
Array.prototype.deleteIndex = function(index){
return this.slice(0, index).concat(this.slice(parseInt(index, 10) + 1));
}
//示例
var test = new Array(1,5,3,4,2);
//输出5
console.log(test.length);
//删除索引为1的元素
test = test.deleteIndex(1);
//输出[1, 3, 4, 2]
console.log(test);
//输出4
console.log(test.length);



