Nodejs Array Remove Object removeObject(obj)

Here you can find the source of removeObject(obj)

Method Source Code

Array.prototype.removeObject = function(obj) {
  var index = this.indexOf(obj);
  if(index !== -1) {
    this.splice(index, 1);// w w w. j  a  v  a  2  s  .c  o m
  }
}

Array.prototype.containsObject = function(obj) {
  return this.filter(item => item === obj).length !== 0;
}

Related

  1. removeByElement(element)
    Array.prototype.removeByElement = function(element){
      for(var i = 0; i < this.length; i++ ){ 
        if(this[i] == element)
          this.splice(i,1); 
    
  2. removeById(id)
    Array.prototype.removeById = function(id){
      for(var i = this.length - 1; i >= 0; i--) {
          if(this[i].id === id) {
             this.splice(i, 1);
      return this;
    };
    
  3. 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;
    
  4. 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;
    };
    
  5. removeObject(element)
    Array.prototype.removeObject = function (element) {
        var i = this.indexOf(element);
        if (i != -1) {
            this.splice(i, 1);
    };
    
  6. removeObject(obj)
    Array.prototype.removeObject=function(obj){
      for(var i=0;i<this.length;i++){
        if(this[i]==obj){
          this.splice(i, 1);
          break;
    
  7. removeObject(object)
    Array.prototype.removeObject = function(object)
        for (var i = 0; i < this.length; ++i)
            if (this[i] === object)
                this.remove(i);
                break;
    Array.prototype.remove = function( from,  to)
      var rest = this.slice((to || from) + 1 || this.length);
      this.length = from < 0 ? this.length + from : from;
      return this.push.apply(this, rest);
    };
    
  8. removeObject(object)
    Array.prototype.removeObject = function(object)
        for (var i = 0; i < this.length; ++i)
            if (this[i] == object)
                this.remove(i);
                break;
    
  9. removeObject(object)
    Array.prototype.removeObject = function(object)
        for (var i = 0; i < this.length; ++i)
            if (this[i] === object)
                this.remove(i);
                break;
    Array.prototype.remove = function( from,  to)
        var rest = this.slice((to || from) + 1 || this.length);
        this.length = from < 0 ? this.length + from : from;
        return this.push.apply(this, rest);
    };