המאפיין length
מאפשר לאחזר את מספר כל הפריטים שנמצאים באחסון המקומי ולהציגם באמצעות מספר שלם.
תחביר
var aLength = Storage.length;
ערך חוזר
מספר שלם.
דוגמאות
הפונקציה הבאה מוסיפה שלושה פריטים לאחסון המקומי ולאחר מכן מחזירה את מספר כל הפריטים שנמצאים באחסון המקומי:
function populateStorage() {
localStorage.setItem('bgcolor', 'yellow');
localStorage.setItem('font', 'Helvetica');
localStorage.setItem('image', 'cats.png');
localStorage.length; // should return 3
}
מפרט
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'Storage.length' in that specification. |
Living Standard |
תאימות דפדפן
BCD tables only load in the browser
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.