Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Storage Object

JavaScript Storage Object

The Web Storage API provides two storage objects, sessionStorage (session storage) and localStorage (local storage), to add, delete, modify, and query data on web pages.

Storage Object Properties

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

Storage Object Methods

Method Description
key(n) Returns the n 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 corresponding value already exists, updates the value for that key.
removeItem(keyname) Removes a key.
clear() Clears all keys in the storage object.

Web Storage API

property Description
window.localStorage Stores key/value pairs in the browser. No expiration time.
window.sessionStorage Stores key/value pairs in the browser. The data is deleted after the window or tab is closed.