Skip to content

Instantly share code, notes, and snippets.

@andreyshr
Last active May 13, 2021 12:00
Show Gist options
  • Save andreyshr/de0f60c0fd32af45d102fff0286abec0 to your computer and use it in GitHub Desktop.
Save andreyshr/de0f60c0fd32af45d102fff0286abec0 to your computer and use it in GitHub Desktop.
Получение размера localStorage
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