Storage length property
- Previous Page key()
- Next Page getItem()
- Go Back to the Previous Level Storage Object
Example
Get the number of local storage items in this domain:
var x = localStorage.length;
Definition and Usage
The length property returns the number of items stored in the browser's Storage object for this specific domain.
The length property belongs to the Storage object and can be localStorage object, which can also be sessionStorage object.
Browser Support
Properties | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
length | 4 | 8 | 3.5 | 4 | 10.5 |
Syntax
localStorage.length;
Or:
sessionStorage.length;
Technical Details
DOM Version: | Web Storage API |
---|---|
Return value: | An integer representing the number of storage items. |
More examples
Example
The same example, but using session storage instead of local storage.
Get the number of session storage items in this domain:
var x = sessionStorage.length;
Example
Loop through each local storage item and display the name:
for (i = 0; i < localStorage.length; i++) { x = localStorage.key(i); document.getElementById("demo").innerHTML += x;
- Previous Page key()
- Next Page getItem()
- Go Back to the Previous Level Storage Object