length
Summary
Returns the number of key/value pairs currently present in the list associated with the object.
Property of apis/web-storage/Storageapis/web-storage/Storage
Syntax
Note: This property is read-only.
var result = object.length;
Return Value
Returns an object of type unsigned longunsigned long
Examples
This example creates two new localStorage items (a timestamp and a user name), then reports the number of key/value pairs (2).
window.localStorage.setItem('timestamp', (new Date()).getTime());
window.localStorage.setItem('user', 'Bob');
alert("There are " + window.localStorage.length + " localStorage item(s)");
Related specifications
- W3C Web Storage Specification
- W3C Editor’s Draft
Attributions
Microsoft Developer Network: Windows Internet Explorer API reference Article