title: Angular 2: Delete object in Array
body: <p>I want to delete an object in an array when that object's ID is equal to the ID of the object getting compared. Currently, it only removes the first object in the array</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>if(this.selectedProducts.length &gt; 0){
        for(let x of this.selectedProducts){
            if(prod._id === x._id){
                this.selectedProducts.splice(x,1);   //this is the part where I 'delete' the object
                this.appended = false;
            }else{
                this.appended = true;
            }
        }
        if (this.appended) {
            this.selectedProducts.push(prod);
        }
    }else{
        this.selectedProducts.push(prod);                
    }
    this.selectEvent.emit(this.selectedProducts);
  }</code></pre>
  </div>
  </div>
  </p>