Storage length property
- Página anterior key()
- Próxima página getItem()
- Voltar à página anterior Objeto Storage
Example
Get the number of local storage items for 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 of the Storage object can be localStorage object, or also 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 for 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; }
- Página anterior key()
- Próxima página getItem()
- Voltar à página anterior Objeto Storage