This article explains how to delete all information saved in browser storage using JavaScript.
Please tell me how to delete information stored in localStorage and sessionStorage in bulk.
By calling the localStorage.clear() and sessionStorage.clear() methods, you can delete information stored in each object at once.
Also, if you want to remove only a specific key/value combination, use the removeItem() method.
What is storage?
Browser storage is an area where you can store information from websites. There are types such as localStorage and sessionStorage, which can store data in key-value format.
How to delete all storage
To delete all contents of localStorage or sessionStorage, call the clear() method provided with each object. The following is sample code.
localStorage.clear();
sessionStorage.clear();
This will delete all information stored in localStorage and sessionStorage at once. If you want to delete only a specific key/value combination, you can do so by setting the value corresponding to that key to null.
localStorage.setItem("key1", "value1");
localStorage.setItem("key2", "value2");
localStorage.removeItem("key1");
In the above code, the key/value combination “key1” and “key2” is first stored in localStorage. Then, using the removeItem() method, the value corresponding to “key1” is removed. This deletes the combination of “key1” and “value1” from localStorage.
summary
We explained how to delete all information saved in browser storage in bulk.
- Browser storage includes localStorage and sessionStorage, which can store data in key-value format.
- All storage contents can be deleted by calling localStorage.clear() and sessionStorage.clear().
- If you want to delete only a specific key/value combination, you can do so using the removeItem() method.
You can now delete information saved in your browser’s storage all at once.
By periodically deleting information, you can continue to use the website comfortably.
Also, storing unnecessary information can take up storage space.
Be sure to delete unnecessary information.
Comments