Nodejs Array Remove All removeAll( func )

Here you can find the source of removeAll( func )

Method Source Code

Array.prototype.removeAll = function( func ) {
   var _retained = [];
   var _removed = [];
   for( var i=0; i<this.length; i++ ) {
      var item = this[i];
      if( !func(item) == true ) {
         _retained.push( item );//from   www  . j  av  a  2  s.  co m
      }
      else {
         _removed.push( item );
      }
   }
   this.length = 0;
   this.push.apply(this, _retained);
   return _removed;
};

Related

  1. removeAll()
    Array.prototype.removeAll = function () {
        while (this.length > 0) {
            this.pop();
    };
    
  2. removeAll()
    Array.prototype.removeAll = function() {
        while(this.length > 0) {
            this.pop();
    };
    
  3. removeAll(element)
    var arr = [1,2,1,4,1,3,4,1,111,3,2,1,'1'];
    Array.prototype.removeAll = function (element){
        var i,
            length = this.length;
        for (i = 0; i < length; i+=1){
            if(this[i] === element){
                this.splice(i, 1);
                i-=1;
                length-=1;
    ...
    
  4. removeAll(element)
    Array.prototype.removeAll = function (element) {
        var newArr = [];
        for (var i in this) {
            if (this[i] != element) {
                newArr.push(this[i]);
        return newArr;
    var arr = [1, 2, 1, 4, 1, "1", 3, 4, 1, 111, 3, 2, 1, "1"];
    var finalArr = arr.removeAll(1);
    for (var i in finalArr) {
        console.log(finalArr[i]);