length Property – How to Get Total Items in Web Storage
The length property returns the number of properties in the specified web storage.
Syntax of the length
Property
Here is length
’s syntax:
webStorageObject
represents the storage object whose length you wish to verify—that is, localStorage
or sessionStorage
.
Examples
Below are examples of the length
property.
How to verify the number of items in session storage
Invoke sessionStorage
’s length
property.
Note that your sessionStorage.length
invocation may return a value greater than 3
if your browser’s session storage already contains some stored information.
How to verify the number of items in local storage
Invoke localStorage
’s length
property.
Note that your localStorage.length
invocation may return a value greater than 3
if your browser’s local storage already contains some stored information.