Scriptbar Snippets 🚀
Handy and easy to understand snippets to keep in your browser
log-local-storage-key-value-size.js

#Basic

Print out current page localStorage values size

Prettyprint out current page localStorage key-values size

log local storage key-value size

// based on answer to question // http://stackoverflow.com/questions/4391575/how-to-find-the-size-of-localstorage (function showLocalStorageSize() { function stringSizeBytes(str) { return str.length * 2; } function toMB(bytes) { return bytes / 1024 / 1024; } function toSize(key) { return { name: key, size: stringSizeBytes(localStorage[key]) }; } function toSizeMB(info) { info.size = toMB(info.size).toFixed(2) + ' MB'; return info; } var sizes = Object.keys(localStorage).map(toSize) .sort((kv1, kv2) => { return kv2.size - kv1.size; }).map(toSizeMB); console.table(sizes); }());
Built with ❤️ by @domnguyen and everyone on the internet 🚀