Easy Tutorial
❮ Prop Option Value Prop Datetime Form ❯

JavaScript Storage Objects

The Web Storage API provides two storage objects, sessionStorage (session storage) and localStorage (local storage), for adding, deleting, modifying, and querying data on web pages.

-

localStorage is used to store data for the entire website permanently. The stored data does not expire and remains until manually removed.

-

sessionStorage is used to temporarily store data for the same window (or tab). This data is deleted after the window or tab is closed.

Storage Object Properties

Property Description
length Returns the number of data items in the storage object.

Storage Object Methods

Method Description
key(n) Returns the name of the nth key in the storage object.
getItem(keyname) Returns the value of the specified key.
setItem(keyname, value) Adds a key and value. If the key exists, it updates the value.
removeItem(keyname) Removes the key.
clear() Clears all keys in the storage object.

Web Storage API

Property Description
window.localStorage Stores key/value pairs in the browser with no expiration time.
window.sessionStorage Stores key/value pairs in the browser. Data is deleted after the window or tab is closed.
❮ Prop Option Value Prop Datetime Form ❯