SessionStorage is a type of web storage that allows you to store key-value pairs in a web browser. The data stored in session storage is specific to the current session or tab, and is deleted when the user closes the tab or browser window.
- Store data in SessionStorage:
- Retrieve data from SessionStorage:
var data = sessionStorage.getItem("key");
- Remove data from SessionStorage:
- Clear all data from SessionStorage:
It’s important to note that data stored in session storage can only be accessed by scripts on the same origin as the data was stored. The maximum size of the data that can be stored in session storage varies between browsers, but is usually around 5-10 MB.
You can also use the length property to get the number of key-value pairs stored in session storage, and the key() method to retrieve the key at a specific index in the storage.