3

Is there a way to remove all local storage properties at once, or do you have to go through and remove each separate property?

<script>localStorage = null</script> 

Something along those lines.
I'm trying to future proof my website; I have a form which I want people to be able to leave and come back to later on, but once they have submitted it, the form data should be cleared from the browser memory. So I can go through and remove each property, but that means if I later add a field, I have to adjust the code on the submit page.

3
  • Use localStorage.clear(); Said here Commented May 29, 2018 at 2:09
  • You can only clear local storage that you set yourself (unless you are using devtool). Commented May 29, 2018 at 2:13
  • Thank you, Marcelo. Commented May 29, 2018 at 2:17

1 Answer 1

4

Use clear to delete entire localStorage object:

localStorage.clear(); 

Check out below link for clear() and other methods of localStorage :

https://developer.mozilla.org/en-US/docs/Web/API/Storage/clear

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.