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
?
Advertisement
Answer
to get a list that shows the keys name and city
Use Object.keys()
function:
JavaScript
x
5
1
sessionStorage.name = 'John';
2
sessionStorage.city = 'New York';
3
4
console.log(Object.keys(sessionStorage));
5