Skip to content
Advertisement

Javascript: Retrieve all keys from sessionStorage?

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:

sessionStorage.name = 'John';
sessionStorage.city = 'New York';

console.log(Object.keys(sessionStorage));
Advertisement