Languages
[Edit]
EN

JavaScript - remove item from localStorage

3 points
Created by:
Jan-Alfaro
681

In this article, we would like to show you how to remove item from localStorage in JavaScript.

Quick solution:

 

Practical example

Edit

To remove items from localStorage, we use removeItem() method that takes the item key as an argument and removes that key from the storage if it exists. If there is no item with the given key, the method will do nothing.

Note: localStorage is BOM (Browser Object Model) global object so we can also access it using window.localStorage.

 

Alternative solution

Edit

As an alternative, you can use delete operator to remove item from the localStorage, however this solution is not recommended.

 

Remove all items

Edit

We use clear() method to remove all items from the localStorage.

 

See also

Edit
  1. JavaScript - how to use localStorage

  2. JavaScript - store array in localStorage

  3. JavaScript - clear localStorage

  4. HTML5 - localStorage vs sessionStorage

References

Edit
  1. Window.localStorage - Web APIs | MDN

Alternative titles

  1. JavaScript - delete value from localStorage
  2. JavaScript - delete value from local storage
  3. JavaScript - remove value from local storage
  4. JavaScript - remove values from localStorage
  5. JavaScript - delete items from localStorage
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join