简体   繁体   中英

Using localstorage.clear() but exclude 1 item

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM