日期:2014-05-16 浏览次数:20375 次
Array.prototype.clean = function(deleteValue) { for (var i = 0; i < this.length; i++) { if (this[i] == deleteValue) { this.splice(i, 1);//返回指定的元素 i--; } } return this; };
test = new Array("","One","Two","", "Three","","Four").clean(""); test2 = [1,2,,3,,3,,,,,,4,,4,,5,,6,,,,]; test2.clean(undefined);
var arr = [1,2,,3,,3,,,0,,,4,,4,,5,,6,,,,]; arr = arr.filter(function(n){return n}); // (javascript 1.6 and above) arr // [1, 2, 3, 3, 4, 4, 5, 6]
var filteredArray = array.filter(callback);