- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Storage length property
The HTML DOM Storage length property is used for getting the number of items that are present inside the browser’s storage object. The storage object can be a localStorage object or a sessionStorage object.
Syntax
Following is the syntax for −
Storage length property using localStorage object −
localStorage.length;
Storage length property using sessionStorage object
sessionStorage.length;
Example
Let us look at the example for the Storage length property −
<!DOCTYPE html> <html> <body> <h1 style="text-align:center">Storage length property example</h1> <p>Get how many storage items are stored in the local storage object by clicking the below button</p> <button onclick="itemNum()">GET NUMBER</button> <p id="Sample"></p> <script> function itemNum() { var num = localStorage.length; document.getElementById("Sample").innerHTML = "Number of storage items are "+num; } </script> </body> </html>
Output
This will produce the following output −
On clicking the GET NUMBER −
Advertisements