Get the number of local storage item for this domain:
var x = localStorage.length;
Use the length property to get the number of items stored in the local storage object.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Get the number of stored items</button> <p id="demo"></p> <script> function myFunction() {/* w w w . j a va 2s .co m*/ var x = localStorage.length; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The length property returns the number of items stored in the browsers Storage Object for this particular domain.
The length property belongs to the Storage Object, which can be either a localStorage object or a sessionStorrage object.