I have many elements in localstorage and I want to clear them all ... except for 1 element, we will call it "X".
Is there a way to call localstorage.clear () but exclude X?
Save the value you want to save in another variable, then use localStorage.clear()
localStorage.clear()
Example:
var myItem = localStorage.getItem('key'); localStorage.clear(); localStorage.setItem('key',myItem);
An example was from this SO post .