Storage getItem() Method
- Previous Page length
- Next Page setItem()
- Go Up One Level Storage Object
Example
Get the value of the specified local storage item:
var x = localStorage.getItem("mytime");
Definition and Usage
getItem() method returns the value of the specified Storage object item.
getItem() method belongs to Storage object, it can be localStorage Object, which can also be sessionStorage Object.
Browser Support
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
getItem() | 4 | 8 | 3.5 | 4 | 10.5 |
Syntax
localStorage.getItem(keyname)
Or:
sessionStorage.getItem(keyname)
Parameter Value
Parameter | Description |
---|---|
keyname | Required. String, specifying the name of the key to get its value. |
Technical Details
DOM Version: | Web Storage API |
---|---|
Return value: | String representing the value of the specified key. |
More examples
Example
The same example, but using session storage instead of local storage.
Get the value of the specified session storage item:
var x = sessionStorage.getItem("test1");
Example
You can also use dot notation (obj.key) to get the value:
var x = sessionStorage.test1;
Example
You can also get the value like this:
var x = sessionStorage["test1"];
Related Page
Web Storage Reference Manual:setItem() Method
Web Storage Reference Manual:removeItem() Method
- Previous Page length
- Next Page setItem()
- Go Up One Level Storage Object