Last active
May 13, 2021 12:00
-
-
Save andreyshr/de0f60c0fd32af45d102fff0286abec0 to your computer and use it in GitHub Desktop.
Получение размера localStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getLocalStorageSize = function() { | |
var total = 0; | |
for (var x in localStorage) { | |
// Value is multiplied by 2 due to data being stored in `utf-16` format, which requires twice the space. | |
var amount = (localStorage[x].length * 2) / 1024 / 1024; | |
if (!isNaN(amount) && localStorage.hasOwnProperty(x)) { | |
total += amount; | |
} | |
} | |
return total.toFixed(2); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment