I have a lot of items in localstorage, and I want to clear them all...except 1 item, we'll call it "X".
Is there a way to call localstorage.clear() but exclude X?
I have a lot of items in localstorage, and I want to clear them all...except 1 item, we'll call it "X".
Is there a way to call localstorage.clear() but exclude X?
Store the value you'd like to keep in another variable, then use localStorage.clear()
Example:
var myItem = localStorage.getItem('key');
localStorage.clear();
localStorage.setItem('key',myItem);
Example was taken from this SO post.