Getting a stored item

A stored item inside the sessionStorage object can be accessed using the sessionStorage.getItem,  sessionStorage.key, or sessionStorage['key'] methods. However, as with localStorage,  it is advisable to make use of getItem to safely get the right storage value instead of a property of the sessionStorage object. 

The following snippet demonstrates how to get a stored item from session storage:

const item = sessionStorage.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.