Normally there is a function localstorage.remove(key). But i want to delete an index within a key. I am saving the object like that:
cart[idstr] = [qty, name];
localStorage.setItem('cart', JSON.stringify(cart));
I want to delete a specific cart[idstr]
Sample console.log(cart)
is giving:
{pr22: Array(2), pr19: Array(2), pr21: Array(2)}
Suppose i want to delete pr19. What should i do?
It is not possible to do it directly.
let cart= JSON.parse( localStorage.getItem('cart') );
delete cart.pr19;
localStorage.setItem('cart', JSON.stringify( cart ) );