Storage: length プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
length
は Storage
インターフェイスの読み取り専用プロパティで、Storage
オブジェクトに保存されているデータアイテムの数を表す整数を返します。
値
Storage
オブジェクトに格納されているアイテムの数です。
例
以下の関数は現在のドメインのローカルストレージに 3 個のデータアイテムを追加して、ストレージ内のアイテムの数を返します。
js
function populateStorage() {
localStorage.setItem("bgcolor", "yellow");
localStorage.setItem("font", "Helvetica");
localStorage.setItem("image", "cats.png");
return localStorage.length; // 3 を返す
}
メモ: 現実世界の例として、 Web Storage Demo をご覧ください。
仕様書
Specification |
---|
HTML # dom-storage-length-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
length |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.