Getting a stored item

A stored item inside a session storage object can be accessed using the localStorage.getItem localStorage.keyor localStorage['key'] methods. We'll take a look at this in more detail a little later, in the localStorage.getItem('key') versus localStorage.key section, where we'll see which method is the best and why not to use other methods; now, though, let's stick with the localStorage.getItem method.

It's easy to get stored items from local storage, as shown in the following snippet:

const item = localStorage.getItem('myKey');console.log(item); // my awesome value

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.