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

How to find the size of localStorage in HTML?

王林
Release: 2023-09-11 10:41:08
forward
787 people have browsed it

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");
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template