Nodejs Array Remove If removeIf(predicate)

Here you can find the source of removeIf(predicate)

Method Source Code

Array.prototype.removeIf = function(predicate)
{
   var count = 0;
   for (var i = 0; i < this.length; i++)
   {//from   ww w. j  a  v  a 2 s  .co m
      if (predicate(this[i]))
      {
         this.splice(i, 1);
         count++;
         i--;
      }
   }
   return count;
}

Related

  1. removeIf(callback)
    Array.prototype.removeIf = function(callback) {
        var i = this.length;
        while (i--) {
            if (callback(this[i], i)) {
                this.splice(i, 1);
    };
    
  2. removeIf(removeFunction)
    Array.prototype.removeIf = function(removeFunction) {
        var index = 0;
        while (index < this.length) {
            if (removeFunction(this[index])) {
                this.splice(index, 1);
            } else {
                index++;
    };
    
  3. removeIfTrue(func)
    Array.prototype.removeIfTrue = function (func) {
      this.forEach((el) => {
        if (func(el)) {
          this.splice(this.indexOf(el, 1))
      })
    
  4. removeOneByPredicate(pr)
    Array.prototype.removeOneByPredicate = function (pr) {
        var index = this.indexOf(this.first(pr));
        if (index != -1) {
            this.splice(index, 1);
            return true;
    };