sessionStorage content not getting removed

1.6k views Asked by At

I have populated the sessionStorage in the following way

var shopcart = [];
if (!itemincart) {
    shopcart.push(iteminfo);
}
sessionStorage["sca"] = JSON.stringify(shopcart);

And now I want to make the sessionStorage completely empty. I have tried several suggestions on this site but could not find any solution till now. Any help will be appreciated.

2

There are 2 answers

1
Ionut Necula On

You can use sessionStorage.clear(); to remove all the data set in sessionStorage or use sessionStorage.removeItem(); to remove just one item in the sessionStorage:

sessionStorage.clear();

or:

sessionStorage.removeItem('sca');

You can read more about this here.

UPDATE:

If you mean you want to clear the sessionStorage[] array, then you can do it by setting it to a new empty array like this:

sessionStorage = [];
0
Rafique Ahmed On

sessionStorage.clear() will remove all session data.