LocalStorage
LocalStorage is a key-value store of strings, where data sticks around even if the user closes the tab or the browser.
Storage is typically limited to around 5Mb of data in most browsers, and the store can be cleared if the user requests it, hasn't visited your site in a while or if the user simply is running out of space.
Still, LocalStorage
can be useful for things like configuration, session
keys or even communication between web applications running on the same
origin domain.
Common operations
Get the value associated with a given key.
Insert the key-value pair into the store. If the key already exist it will be overwritten. If it doesn't exist, it will be added.
Remove the key-value pair from the store.
Remove all key-value pairs from the store.
Discovery
Gets the number of key-value pairs in the store. You can use this
to check if the store is empty, or in combination with keyAtIndex
and
get
to read out every key-value pair that has been stored.
Let's you find the nth key in the store. Keep in mind that keys are not stored in any particular order. So calling this function with index 0 will not necessarily return the first key that was stored.