Andross
Andross

Reputation: 246

Delete Entire Local Storage Object

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.

Upvotes: 3

Views: 91

Answers (1)

Vikasdeep Singh
Vikasdeep Singh

Reputation: 21766

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

Upvotes: 4

Related Questions