Nodejs Array Remove Object removeById(id)

Here you can find the source of removeById(id)

Method Source Code

Array.prototype.removeById = function(id){
   for(var i = this.length - 1; i >= 0; i--) {
       if(this[i].id === id) {
          this.splice(i, 1);// www  .  jav a2 s .c  o m
       }
   }
   return this;
};

Related

  1. removeByObj(obj)
    Array.prototype.removeByObj = function(obj) {
      for(var i = 0 ; i < this.length ; i++) {
        if(this[i] === obj) {
          this.splice(i,1);
          return;
      console.trace("[removeByObj] failed for " + obj);
    };
    ...
    
  2. removeByObj(obj)
    Array.prototype.removeByObj = function(obj) {
      for(var i = 0 ; i < this.length ; i++) {
        if(this[i] === obj) {
          this.splice(i,1);
          break;
    };
    
  3. removeElement(obj)
    Array.prototype.removeElement = function(obj) {
        var i = this.length;
        while (i--) {
            if (angular.equals(this[i], obj)) {
              this.splice(i,1);
    };
    
  4. removeByElement(element)
    Array.prototype.removeByElement = function (element) {
      for(var i=0; i<this.length;i++ ){ 
          if(this[i]==element){
            this.splice(i,1);
    
  5. removeByElement(element)
    Array.prototype.removeByElement = function(element){
      for(var i = 0; i < this.length; i++ ){ 
        if(this[i] == element)
          this.splice(i,1); 
    
  6. removeById(id)
    Array.prototype.removeById = function(id) {
        for(var i=0; i<this.length; i++) {
            if(this[i]._id == id) {
                this.splice(i, 1);
                break;
    
  7. removeById(id)
    Array.prototype.removeById = function(id) {
      for(var i = 0 ; i < this.length ; i++) {
        if(this[i].id == id) {
          this.splice(i,1);
          break;
    };
    
  8. removeObject(element)
    Array.prototype.removeObject = function (element) {
        var i = this.indexOf(element);
        if (i != -1) {
            this.splice(i, 1);
    };
    
  9. removeObject(obj)
    Array.prototype.removeObject = function(obj) {
      var index = this.indexOf(obj);
      if(index !== -1) {
        this.splice(index, 1);
    Array.prototype.containsObject = function(obj) {
      return this.filter(item => item === obj).length !== 0;