Using localstorage.clear (), but exclude 1 element

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?

+7
javascript local-storage
source share
1 answer

Save the value you want to save in another variable, then use localStorage.clear()

Example:

 var myItem = localStorage.getItem('key'); localStorage.clear(); localStorage.setItem('key',myItem); 


An example was from this SO post .

+16
source share

All Articles