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 −
