How to remove an item from localStorage in JavaScript

Removing specific items from localStorage is crucial for managing browser storage efficiently and maintaining clean application state. As the creator of CoreUI with extensive JavaScript experience since 2000, I’ve implemented localStorage management in numerous web applications and UI components. From my expertise, the most straightforward approach is using the localStorage.removeItem() method with the specific key name. This method safely deletes individual items while preserving other stored data.

Use localStorage.removeItem() with the key name to delete specific items from browser storage.

localStorage.removeItem('username')

Here localStorage.removeItem('username') removes the item with the key ‘username’ from localStorage. The method operates silently - if the key doesn’t exist, no error is thrown. This approach allows selective deletion of stored data without affecting other localStorage entries. The removed item becomes undefined and can no longer be retrieved, freeing up storage space in the browser.

Best Practice Note:

This is the same approach we use in CoreUI components for cleaning up temporary data and user session management. Always remove localStorage items when they’re no longer needed to prevent storage bloat and maintain optimal application performance.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to Clone an Object in JavaScript
How to Clone an Object in JavaScript

How to Achieve Perfectly Rounded Corners in CSS
How to Achieve Perfectly Rounded Corners in CSS

How to replace all occurrences of a string in JavaScript?
How to replace all occurrences of a string in JavaScript?

How to Open All Links in New Tab Using JavaScript
How to Open All Links in New Tab Using JavaScript

Answers by CoreUI Core Team