Storage length 属性
描述
length 属性返回浏览器 Storage 对象中,对于特定域已存储的项的数量。
length 属性属于 Storage 对象,该对象可以是 localStorage 对象或 sessionStorage 对象。
浏览器支持
属性 | |||||
---|---|---|---|---|---|
length | 4 | 8 | 3.5 | 4 | 10.5 |
语法
localStorage.length;
或
sessionStorage.length;
技术详情
DOM 版本 | Web Storage API |
---|---|
返回值 | 一个整数,表示已存储项的数量 |
更多示例
示例
遍历每个本地存储项并显示名称
for (i = 0; i < localStorage.length; i++) {
x = localStorage.key(i);
document.getElementById("demo").innerHTML += x;
}
自己动手试一试 »