[Vuejs]-Delete items in Vue component, it’s not working(( I tried to deploy it on heroku and was failed((

1👍

✅

In removeIngredients (value) method you are not removing anything from ingredients. You can try a better solution than using filter, but it’s correct use is:

this.ingredients = this.ingredients.filter(item => item !== value);

because it needs a boolean to perform a comparison.

Edit

To have also some logs from the find function you can try using the curly braces block in your lambda expression:

this.ingredients = this.ingredients.filter(item => {
  item !== value ? console.log(this.ingredients, item) : -1;
  return item !== value;
});

To permanently remove an element without reassigning this.ingredients you can use splice method:

conat index = this.ingredients.findIndex(item => item === value);
if (index > -1) {
  this.ingredients.splice(index, 1);
}

Leave a comment