> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/storage/sessionstorage.md).

# sessionStorage

Enhanced session Storage

Provides automatic JSON handling for `sessionStorage`.

* `setSessionItem(key, value)`: Stores a value (automatically stringifies objects).
* `getSessionItem(key)`: Retrieves a value (automatically parses JSON if applicable).

You can now store and retrieve objects in the session storage without needing to parse or stringify them.

#### Usage

```javascript
setSessionItem('user', { name: 'John', age: 30 });
const user = getSessionItem('user');
console.log(user.name);// John
```

```javascript
// Storing an array
setSessionItem('items', [1, 2, 3, 4]);
const items = getSessionItem('items');
console.log(items);// [1, 2, 3, 4]
```

```javascript
// Storing a nested object
setSessionItem('settings', { theme: 'dark', notifications: { email: true, sms: false } });
const settings = getSessionItem('settings');
console.log(settings.theme);// dark
console.log(settings.notifications.email);// true
```

```javascript
setSessionItem('theme','light');
const preferredTheme = getSessionItem('theme');
console.log(preferredTheme);
```

#### Clearing or removing items

```javascript
clearSessionItems();//Clears all session storage items for the current site. 

removeSessionItem('settings');//Removes one session storage item.
```
