Ad

How To Remove An Item From An Array?

I have this

<span @click="remove(product)" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></span> element, It triggers this function:<br/>

remove(product) {
  this.form.products.$remove(product);
} <br/>

But it outputs this error:TypeError: this.form.products.$remove is not a function i don't know what is wrong.

Ad

Answer

Use the splice method to remove the item from an array

First get the index of the item

let index = this.form.products.indexOf(product);

Then remove it using splice

this.form.products.splice(index,1);
Ad
source: stackoverflow.com
Ad