Skip to main content
16-Pearl
April 17, 2025
Solved

How to clear/remove array in sessionStorage

  • April 17, 2025
  • 1 reply
  • 1241 views
 
I am storing array in sessionstorage. I'm able to update the array using 
sessionStorage.setItem(Op_withoutSpaces + "_" + i, array);
 
but i couldn't remove or clear the array in sessionstorage using below code. 
sessionStorage.clear(Op_withoutSpaces + "_" + i);
sessionStorage.RemoveItem(Op_withoutSpaces + "_" + i);
 
Let me know what is wrong in this.
Best answer by TonyZhang

Hi @AP_10343008,

 

First of all, TW.sessionStorage.clear() function doesn't accept any arguments, this function will clear ALL items in sessionStorage.

Refer to MDN document.

So you are not supposed to pass anything in the parenthesis like below.

TW.sessionStorage.clear(Op_withoutSpaces + "_" + i);

Secondly, can you try removing other code and passing hard-coded key name to TW.sessionStorage.RemoveItem("key") instead of parameter for testing purpose?

I tested both TW.sessionStorage.clear and TW.sessionStorage.RemoveItem("key") in expression and both work just fine.

 

1 reply

16-Pearl
April 17, 2025

Hi @AP_10343008  can you use it in the format below?

TW.sessionStorage.removeItem()
TW.sessionStorage.clear()
16-Pearl
April 21, 2025

Still it is not working. I uploaded the code which written in the expression of mashup. Kindly take a look.

 

 

16-Pearl
April 24, 2025

Anyone knows why remove item is not working in session ? Please find the code i have attached.