Reputation: 59
I want to proof if an item exists in localStorage, where the itemID matches a string, to remove it. The clear function works fine, but not without removing everything. Is there any way to do it?
var myMatch = "test";
localStorage.setItem("test_1", "value");
-> localStorage.getItem(); // ?
Upvotes: 0
Views: 2264
Reputation: 21756
localstorage
has function getItem()
instead of get()
.
So change:
localStorage.get(itemID);
To:
localStorage.getItem(itemID);
So your final code will be like below:
var myMatch = "test";
if (localStorage.getItem(itemID) === myMatch) {
localStorage.removeItem(itemID)
}
For more information in localStorage
please check here.
Upvotes: 1