Javascript: Retrieve all keys from sessionStorage?

TheStoryCoder picture TheStoryCoder · Jan 24, 2017 · Viewed 15.6k times · Source

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?

Answer

RomanPerekhrest picture RomanPerekhrest · Jan 24, 2017

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));