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.