How to get an item from sessionStorage in JavaScript

Retrieving items from sessionStorage allows access to temporary data stored during the current browser session for form restoration and state management. With over 25 years of experience in software development and as the creator of CoreUI, I’ve implemented sessionStorage retrieval in form handlers, navigation state, and temporary user preferences. From my expertise, the most straightforward approach is using the sessionStorage.getItem() method which returns stored values by their key names. This method provides reliable access to session-specific data that automatically clears when the tab closes.

Use sessionStorage.getItem() to retrieve temporarily stored data by its key name.

const tempData = sessionStorage.getItem('tempData')
console.log(tempData)

Here sessionStorage.getItem('tempData') retrieves the value associated with the key ’tempData’ from sessionStorage. The method returns the stored string value, or null if the key doesn’t exist or has been cleared. For complex data structures that were stored as JSON strings, use JSON.parse() to convert them back to objects. SessionStorage data is available throughout the current tab session but gets automatically cleared when the tab closes.

Best Practice Note:

This is the same approach we use in CoreUI components for restoring temporary form states, maintaining wizard progress, and retrieving session-specific settings. Always check for null values when retrieving sessionStorage items since they may not exist or could have been cleared by browser storage limits.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author