Hello everyone, I am having a bit of an issue understanding how to use the array.filter method. Whenever I have used it It has been on an array of numbers.
But now I am trying to use it on an array of objects.
the objects look like this
1:
desc: "description"
id: "Bronze commoners' axe"
image: "/itemphotos/bronzeage/axe.jpg"
price: 25
title: "Bronze commoners' axe"
And I am trying to use the filter method to sort through the array and take out anything with a matching id, and then set the state to that new array.
Removefromcart = (id, price) => {
this.setState((state) => ({
cart: this.state.cart.filter((value) => value !== id),
// total: state.total - price
}));
console.log(this.state.cart);
};
It seems no matter what I do here it never filters out the item. It has been a very long time since I have worked with array methods like this, so any help would be appreciated. Thank you.