I know that with localStorage.removeItem(key)
I can remove an item by key. If my localStorage
were single-dimensional (i.e. localStorage.search_near = 60654
), that would be fine.
But I have multilevel values.
My localStorage.storedAddresses
contains json objects:
[{
"storeNumber": "010517",
"zip": "20500",
"state": "DC",
"city": "WASHINGTON",
"address": "1600 Pennsylvania Ave",
"zone": null,
"address_two": null,
"name": "Second Choice",
"type": "P",
"dwellCode": "P",
"key": 4,
"defaultLocation": "N"
},
{
"storeNumber": "714389",
"zip": "60202",
"state": "IL",
"city": "EVANSTON",
"address": "818 Brown Ave",
"zone": null,
"address_two": null,
"name": "Test Storage",
"type": "P",
"dwellCode": "P",
"key": 3,
"defaultLocation": "N"
},
{
"storeNumber": "316740",
"zip": "70810",
"state": "LA",
"city": "BATON ROUGE",
"address": "9884 BLUEBONNET BLVD",
"zone": null,
"address_two": null,
"name": "Test2",
"type": "P",
"dwellCode": "P",
"key": 2,
"defaultLocation": "N"
}]
How would I go about using localStorage.removeItem()
to remove just the object where storeNumber
is 714389? Do I have to loop through localStorage.storedAddresses
and compare the storeNumber values, and then use removeItem
when it finds the match? Or is there a more direct way?