Currently, I am attempting to remove individual items from the cart that is stored in localStorage. However, I have only been successful in deleting the entire array using methods like removeItem() or clear(). My goal is to delete specific items based on their id. When trying to use the splice method, I encounter an error. As I am still learning, please let me know if more information is needed.
deleteProduct: (index) => {
const existingEntries = JSON.parse(localStorage.getItem("cartData"));
existingEntries.splice(index, 1);
localStorage.setItem("cartData", JSON.stringify(existingEntries));
}
let cartData = window.localStorage.getItem('cartData');
const cart = {
state: {
cartData: cartData ? JSON.parse(cartData) : {
foods: [],
totalPrice: [],
Quantities: []
},
},