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.

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
Andross
  • 105
  • 1
  • 8

1 Answers1

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

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104