English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
lengthStorage length attribute
The length property of the storage object is a read-only property that returns the number of data items stored in the given Storage object.localStorageObject orsessionStorrageObject.
localStorage.length
sessionStorage.length
var x = localStorage.length;Test and See‹/›
The numbers in the table specify the first browser version that fully supports the length property:
Property | |||||
length | 4 | 3.5 | 11.5 | 4 | 9 |
Return Value: | An integer representing the number of storage items |
---|---|
DOM Version: | Web Storage API |
The following function adds two data items to the session storage of the current domain and then returns the number of items in the storage:
function myFunc() { sessionStorage.setItem(&39;name&39;, &39;Seagull&39;); sessionStorage.setItem(&39;age&39;, &39;22'); var x = sessionStorage.length; }Test and See‹/›
HTML Tutorial:Web Storage API
Window (Window) Reference:window.localStorage Property
Window (Window) Reference:window.sessionStorage Property