日期:2014-05-17 浏览次数:20458 次
<script>
Array.prototype.del = function(val){
if(!val) return this;
var i = 0,
len = this.length;
for(; i < len; i++) {
if(this[i]["b"] === val) {
return this.slice(0, i).concat(this.slice(i + 1, this.length));
}
}
};
var test = [{a:"1",b:2},{a:"5",b:3}];
alert(JSON.stringify(test.del(3)));
</script>
<script type="text/javascript">
Array.prototype.del = function(val){
if(!val) return this;
var i = 0
n = 0,
len = this.length;
for(; i < len; i++) {
if(this[i]["b"] != val) {
this[n++]=this[i];
}
}
//console.log(i,n);
this.length-=i-n;
return this;
};
var test = [{a:"1",b:2},{a:"5",b:3},{a:"6",b:3},{a:"6",b:4}];
alert(JSON.stringify(test.del(3)));
</script>