--- title: Storage.length slug: Web/API/Storage/length tags: - API - Property - Read-only - Reference - Storage - Web Storage translation_of: Web/API/Storage/length ---
{{APIRef("Web Storage API")}}
{{domxref("Storage")}} インターフェイスの読み取り専用プロパティ length
は、Storage
オブジェクトに保存されているデータアイテムの数を表す整数を返します。
var aLength = storage.length;
整数
以下の関数はカレントドメインのローカルストレージに 3 個のデータアイテムを追加して、ストレージ内のアイテムの数を返します:
function populateStorage() { localStorage.setItem('bgcolor', 'yellow'); localStorage.setItem('font', 'Helvetica'); localStorage.setItem('image', 'cats.png'); localStorage.length; // 3 を返す }
注記: 実際の例として、Web Storage Demo をご覧ください。
仕様書 | 策定状況 | コメント |
---|---|---|
{{SpecName('Web Storage', '#dom-storage-length', 'length')}} | {{Spec2('Web Storage')}} |
{{Compat("api.Storage.length")}}