English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JS DOM Reference Manual

JavaScript Storage Object

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.

Syntax:

localStorage.length
sessionStorage.length
var x = localStorage.length;
Test and See‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the length property:

Property
length43.511.549

Technical Details

Return Value:An integer representing the number of storage items
DOM Version:Web Storage API

More Examples

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‹/›

Related References

HTML Tutorial:Web Storage API

Window (Window) Reference:window.localStorage Property

Window (Window) Reference:window.sessionStorage Property

JavaScript Storage Object