Attribute | Description | Sample code |
|---|---|---|
length | This parameter is a variable instead of a function. It is used to obtain the number of data items (read-only) stored in the localStorage object. | console.log(localStorage.length) |
API | Description |
|---|---|
Clears data in localStorage. | |
Deletes a single data record from localStorage by key. | |
Saves data to localStorage. | |
Queries a single data record in localStorage by key. | |
Queries the key data by index. |
Parameter | Type | Mandatory | Description |
|---|---|---|---|
key | string | Yes | Key of the data to be deleted. |
localStorage.removeItem("myKey"); Parameter | Type | Mandatory | Description |
|---|---|---|---|
key | string | Yes | Key of the data to be stored in localStorage. The maximum size of the data corresponding to a key is 1 MB, and the maximum size of all data is 10 MB. |
value | string | Yes | Value of the data to be stored in localStorage. |
localStorage.setItem("myKey", JSON.stringify({'a': 'a'}));