willnew
willnew

Reputation: 153

Can I just remove data in localStorage by its key?

I am learning about HTML5 these days.

Here comes trouble when I want to remove just one of the data in the localStorage.

I know a method called clear() to remove anything, but what can I do if I just remove one of the data by its key?

Upvotes: 15

Views: 18419

Answers (2)

Muhammad Liaquat
Muhammad Liaquat

Reputation: 647

sessionStorage.removeItem('UserName');
localStorage.removeItem('UserName');

Upvotes: 64

Alexander Pavlov
Alexander Pavlov

Reputation: 32286

Does delete window.localStorage["foo"] not work for you for some reason?

Upvotes: 2

Related Questions