unable to store object in session Storage
In this image you can see I am getting an array of objects and at Zero position I am getting some objects Now my task is to store these objects in sessionStorage.
sessionStorage.setItem("mytime",JSON.stringify(data[0]));
When I am checking in sessionStorageis showing an Empty object.
Solution 1:
There is a difference b/w sessionStorage and localStorage.
The sessionStorage
is available only for that particular session i.e if a browser is reloaded, you will no longer be able to access the data. However, localStorage
is persistent and will be available until you explicitly remove it.
If the value is empty, you need to check the value of data[0]
.
localStorage.setItem('mytest', 'Check the local storage console');
console.log(localStorage.getItem('mytest'));