sessionStorage setItem is deleting previous keys

158 views Asked by At

I am trying to save a simple item into sessionStorage so in order to achieve this I am simply writing sessionStorage.setItem('usr', JSON.stringify(data.user)); and later I need to save a different key pair so I write sessionStorage.setItem('u_p', JSON.stringify(page.data)); but this action will result in the deletion of the previous key so I end it up with only the key 'u_p' and the key 'usr' gets deleted.

I tried writing in the same document sessionStorage.setItem('test1', 'value'); sessionStorage.setItem('test2', 'value'); to check if I maybe clearing the sessionStorage in other part of my code but still will save only the last one listed.

Why is this could be happening? Is there a way I can debug this problem?

Thank you

1

There are 1 answers

0
German Gabriel On

Ok, after stack26 answer I just console.log(sessionStorage) and indeed all the key pairs were present in there.

So the conclusion is that the key pairs weren't stacking visually in the console for me to see them but definitely, they were saving it correctly and I can access them anytime.

Thank you