I want to remove multiple sessionStorage values using key/s, One way is I can remove it one by one like this sessionStorage.removeItem('key1') & sessionStorage.removeItem('key2') and so on.
So is there a way that I can remove multiple values like this easy sessionStorage.removeItem('key1', 'key2') or sessionStorage.removeItem(['key1', 'key2'])
You can only remove items one at a time (MDN link, spec link). (Of course, you can use a list of keys and any looping construct.)
You could store your items as an array under a single key (using JSON.stringify when storing, JSON.parse when loading), and then you could remove the entire array (or replace it with an empty one) in one operation.
There is no such way, however there is something else you could do.
Instead of storing individual items you could store objects with multiple properties and then when you remove one you get rid of all its properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With