How to remove and clear all localStorage data

itsme picture itsme · May 22, 2012 · Viewed 229.5k times · Source

I need to clear all data i set into localStorage. By this, I mean completely reset localStorage to null when users remove their accounts.

How can i do that with a simple function?

I tried this:

function clearLocalStorage(){
    return localStorage= null;
}

But it doesn't work as expected.

Answer

Lyn Headley picture Lyn Headley · May 22, 2012

localStorage.clear();

should work.