The JavaScript Window sessionStorage property is an object that provides access to the session storage of the current browser window. It allows you to store and retrieve data using key-value pairs, and the data is automatically deleted when the user closes the window or navigates to a different website.
Here are some examples of how the sessionStorage property can be used in JavaScript code:
- To store a value in the session storage, you can use the following code:
// store the value in the session storage
sessionStorage.setItem('key', 'value');
- To retrieve a value from the session storage, you can use the following code:
// retrieve the value from the session storage
var value = sessionStorage.getItem('key');
- To remove a value from the session storage, you can use the following code:
// remove the value from the session storage
sessionStorage.removeItem('key');
Overall, the sessionStorage property provides a convenient way to store and retrieve data in the session storage of the current browser window. It allows you to store data that is automatically deleted when the user closes the window or navigates to a different website, and it is a useful tool for tasks such as saving user preferences or other temporary data.
Leave a Reply