Storage length Property
Example
Get the number of local storage item for this domain:
var x = localStorage.length;
Try it Yourself »
Description
The length property returns the number of items stored in the browsers Storage Object, for this particular domain..
The length property belongs to the Storage Object, which can be either a localStorage object or a sessionStorrage object.
Browser Support
Property | |||||
---|---|---|---|---|---|
length | 4 | 8 | 3.5 | 4 | 10.5 |
Syntax
localStorage.length;
Or:
sessionStorage.length;
Technical Details
DOM Version: | Web Storage API |
---|---|
Return Value: | A Integer, representing the number of stored items |
More Examples
Example
The same example, but using session storage instead of local storage.
Get the number of session storage item for this domain:
var x = sessionStorage.length;
Try it Yourself »
Example
Loop through each local storage item and display the names:
for (i = 0; i < localStorage.length; i++) {
x = localStorage.key(i);
document.getElementById("demo").innerHTML += x;
}
Try it Yourself »