Javascript Array removeAll()
Array.prototype.removeAll = function () { while (this.length > 0) { this.pop();/*from w ww . ja v a 2 s . co m*/ } };
Array.prototype.removeAll = function () { var what, a = arguments, L = a.length, ax; while (L && this.length) { what = a[--L];/* ww w . j a va 2s. c om*/ while ((ax = this.indexOf(what)) !== -1) { this.splice(ax, 1); } } return this; };
function RemovingAlgorithm(arr, index) { for (var i = index; i < arr.length; i++) {/*from w w w. j a v a2 s . c o m*/ arr[i] = arr[i + 1]; } return arr; } function RemoveAll(value) { for (var i = 0; i < this.length; i++) { if (arr[i] == value) { RemovingAlgorithm(arr, i); i--; } } return arr; } Array.prototype.RemoveAll = RemoveAll; var arr = new Array(); arr = [1, 2, 3, 4, 5, 6, 6, 7, 8, 6]; var newArr = arr.RemoveAll(6); for (var i = 0; i < newArr.length; i++) { if (newArr[i] != undefined) { jsConsole.write(newArr[i] + " "); } }
Array.prototype.removeAll = function() { for( var i=this.length-1; i>=0; i-- ){ this[i]=null;// w w w . j a v a 2 s. com } this.length=0; };