HTML5 JS API Index > Web Storage Tutorials & Specs
Each Storage object provides access to a list of key/value pairs, which are
sometimes called items. Keys are strings. Any string (including the empty string) is a valid key. Values are similarly strings.
- The length attribute must return the number
of key/value pairs currently present in the list associated with the object.
- The clear() method must atomically cause the
list associated with the object to be emptied of all key/value pairs, if there are any. If there
are none, then the method must do nothing.
- getItem(DOMString key)
- The getItem(key) method
must return the current value associated with the given key. If the given key does not exist in the list associated with the object then this method must
- key(unsigned long index)
- The key(n) method must
return the name of the nth key in the list. The order of keys is user-agent
defined, but must be consistent within an object so long as the number of keys doesn't change. (Thus, adding or removing a key may change the order of the keys, but merely
changing the value of an existing key must not.) If n is
greater than or equal to the number of key/value pairs
in the object, then this method must return null.
- removeItem(DOMString key)
- The removeItem(key)
method must cause the key/value pair with the given key to be removed from the
list associated with the object, if it exists. If no item with that key exists, the method must do
- setItem(DOMString key, DOMString value)
- The setItem(key, value) method must first check if a key/value pair with the given key already exists in the list associated with the object.