This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



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


Note: This property is read-only.

var result = object.length;

Return Value

Returns an object of type unsigned longunsigned long


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