Skip to main content

Storage

The Storage interface of the Web Storage API provides access to a particular domain's session or local storage. It allows, for example, the addition, modification, or deletion of stored data items.

MDN Reference

Indexable

[name: string]: any

Methods

clear()

clear(): void;

The clear() method of the Storage interface clears all keys stored in a given Storage object.

MDN Reference

Returns

void


getItem()

getItem(key): string | null;

The getItem() method of the Storage interface, when passed a key name, will return that key's value, or null if the key does not exist, in the given Storage object.

MDN Reference

Parameters

ParameterType
keystring

Returns

string | null


key()

key(index): string | null;

The key() method of the Storage interface, when passed a number n, returns the name of the nth key in a given Storage object. The order of keys is user-agent defined, so you should not rely on it.

MDN Reference

Parameters

ParameterType
indexnumber

Returns

string | null


removeItem()

removeItem(key): void;

The removeItem() method of the Storage interface, when passed a key name, will remove that key from the given Storage object if it exists. The Storage interface of the Web Storage API provides access to a particular domain's session or local storage.

MDN Reference

Parameters

ParameterType
keystring

Returns

void


setItem()

setItem(key, value): void;

The setItem() method of the Storage interface, when passed a key name and value, will add that key to the given Storage object, or update that key's value if it already exists.

MDN Reference

Parameters

ParameterType
keystring
valuestring

Returns

void

Properties

length

readonly length: number;

The length read-only property of the Storage interface returns the number of data items stored in a given Storage object.

MDN Reference