Home  >  Article  >  Web Front-end  >  How to find the size of localStorage in HTML?

How to find the size of localStorage in HTML?

王林
王林forward
2023-09-11 10:41:08758browse

How to find the size of localStorage in HTML?

#localStorage is used to save information across multiple sessions. Its maximum size is 5MB.

Example

You can try running the following code snippet to check the allocated size -

var sum = 0;

// loop for size
for(var i in localStorage) {
   var amount = (localStorage[i].length * 2) / 1024 / 1024;
   sum += amount;
   document.write( i + " = " + amount.toFixed(2) + " MB");
}
document.write( "Total = " + sum.toFixed(2) + " MB");

The above is the detailed content of How to find the size of localStorage in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete