Hello I know there are many questions similar to this but nothing fits my problem.
I have a key value in my localstorage called 'productsInCart'. This key value contains a JSON object which looks like this:
{"11011001":{"id":11011001,"name":"42 Cable","price":4,"inCart":1},"11011002":{"id":11011002,"name":"22 Cable","price":4,"inCart":1}}
Now i want to delete/remove one value for example the value with the id '11011002'. How can I do that?
What I tried so far:
var items = JSON.parse(localStorage.getItem("productsInCart"));
for (var i = 0; i < items.length; i++) {
var items = JSON.parse(items[i]);
if (items.item_id == item_id) {
items.splice(i, 1);
}
}
items = JSON.stringify(items);
localStorage.setItem("productsInCart", items);
I know this wont work because its not an array, but maybe someone has an idea on how to change it?