I am creating a shopping cart.
Basically, when I reload the page with the products in my cart, the local storage doesn’t refresh, which is what I want.
But I also want it to refresh at some point only (when I open another page). How do I get the local storage to refresh completly?
>Solution :
The clear() method of the Storage interface clears all keys stored in a given Storage object.
for example
//feeds storage
localStorage.setItem('foo', 'bar');
localStorage.setItem('john', 'wick');
localStorage.setItem('joe', 'doe');
//lets get the value bar from the localStorage
console.log(localStorage.getItem('foo'))//outputs 'bar'
//clears all data
localStorage.clear();
//now if you try to do it again after you clear it will print null
console.log(localStorage.getItem('foo'))//outputs null