Array.prototype.indexOf = function(val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
$(document).ready(function(){
//声明数组
var str=["小刘","小屋","笑死","小三","小李","小红"];
alert("删除前的长度:"+str.length);
//删除笑死元素
str.remove("笑死");
alert("删除后的长度:"+str.length);
//查看删除后的元素
for(var i=0;i<str.length;i++){
alert(str[i]);
}
});
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
$(document).ready(function(){
//声明数组
var str=["小刘","小屋","笑死","小三","小李","小红"];
alert("删除前的长度:"+str.length);
//删除笑死元素
str.remove("笑死");
alert("删除后的长度:"+str.length);
//查看删除后的元素
for(var i=0;i<str.length;i++){
alert(str[i]);
}
});