Is it not posssible to retrieve all keys/objects that I stored in sessionStorage (or localStorage)?
If I have done sessionStorage.name = 'John'
and sessionStorage.city = 'New York'
, isn't there a way to get a list that shows the keys name
and city
?
to get a list that shows the keys name and city
Use Object.keys()
function:
sessionStorage.name = 'John';
sessionStorage.city = 'New York';
console.log(Object.keys(sessionStorage));
With this you can assign all the data in local storage into an object:
let storage = {}
Object.keys(localStorage).forEach((key) => {
storage[key] = localStorage.getItem(key);
});
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