4

I'm trying to remove item from localStorage in javasscript but it doesn't work.

It only works manually for the sequence of the following events

Right click --> Inspect element --> Resources --> localStorage --> Right click --> Delete 

I tried:

localStorage.clear(); 

and

localStorage.removeItem(key); // the key is the link of the page and 
                              // the value is the selected word in the page 

and both didn't work, I can save item using localStorage.setItem(key, vaule) and get items from localStorage using localStorage.getItem(key) but I can't remove them.

2
  • 1
    a code example that isn't working would help us help you. Commented Feb 13, 2013 at 22:26
  • this is the only thing is not working , i want to remove the old values and put another each time i use this "function" so everything is perfect unless localStorage.clear(), it won't remove anything Commented Feb 13, 2013 at 22:54

2 Answers 2

4

what your looking for is this:

deleter void removeItem(DOMString key);

You could implement this like so:

localStorage.removeItem(key)

Everything about local storage can be found here on the W3 html5 spec for web storage.

You may find this document more helpful as it goes into more explanation.

*Local storage is not a finished spec and these could change.

Sign up to request clarification or add additional context in comments.

1 Comment

the first one after it i can't save values anymore. and the second one didn't work. in my code i want to remove the values to set another value. thank u i will try to check the wensite
-2

localStorage.clear without the () currently works in major browsers.

1 Comment

Does it? localStorage.clear isn't a function call. localStorage.clear() is. And since Clear localStorage opts for (), I think that might be correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.