Some Java Guy
Some Java Guy

Reputation: 5118

How to retrieve all localStorage values

I have used localStorage["key"] and key being different strings to store my values while developing my app.

Now I don't even know what all keys I have used.

Is there a way to retrieve all key's and its values from my file system?

And is there a way to drop the entire localStorage?

Upvotes: 1

Views: 259

Answers (2)

Some Java Guy
Some Java Guy

Reputation: 5118

localStorage.clear(); worked just right for dropping!

But the other question of knowing and retrieving all key-value pair still remains.

Upvotes: 2

McGarnagle
McGarnagle

Reputation: 102743

You can use the iterator to get all the keys...

for (var key in localStorage) {
    console.log(key + ": " + localStorage[key]);
}

Per oneofthelions, localStorage.clear() works to remove all items.

Upvotes: 0

Related Questions