Edit in GitHubLog an issue

window.localStorage

Provides a local key-value store useful for setting preferences and other kinds of data. This data is technically persistent, but can be cleared in a variety of ways, so you should not store data using localStorage that you cannot otherwise reconstruct.

length : number

Read only Number of items stored in the local storage.

key(index)

Returns the name of the nth key in the local storage.

Returns: string - Name of the key. If the index does not exist, null is returned.

ParamTypeDescription
index
number
Integer representing the number of the key

getItem(key)

Gets the value for the key from the local storage. Returns null if the key does not exist.

Returns: string - Value corresponding to the key as string. If the key does not exist, null is returned.

ParamTypeDescription
key
string
Key to retrieve the value of.

setItem(key, value)

Adds key and value to the local storage. Updates the value if the given key already exists.

Throws:

  • Error If it fails to store
ParamTypeDescription
key
string
Key to set value
value
string
Value for the key

removeItem(key)

Removes a key/value pair from the local storage if it exists. Nothing happens if there's no item associated with the given key.

ParamTypeDescription
key
string
Key to remove

clear()

Remove all key/value pairs from the local storage.

Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.