Get the value of the specified local storage item:
var x = localStorage.getItem("mytime");
Try it Yourself »
The getItem() method returns value of the specified Storage Object item.
The getItem() method belongs to the Storage Object, which can be either a localStorage object or a sessionStorage object.
Method | |||||
---|---|---|---|---|---|
getItem() | 4 | 8 | 3.5 | 4 | 10.5 |
localStorage.getItem(
keyname)
sessionStorage.getItem(
keyname)
Parameter | Description |
---|---|
keyname | Required. A String specifying the name of the key you want to get the value of |
DOM Version: | Web Storage API |
---|---|
Return Value: | A String, representing the value of the specified key |
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");
Try it Yourself »
You can also get the value by using dot notation (obj.key):
var x = sessionStorage.test1;
Try it Yourself »
Web Storage Reference: setItem() Method
Web Storage Reference: removeItem() Method
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!