Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

detect localstorage limit

// 1)
function getLocalStorageSpace(){
        var allStrings = '';
        for(var key in window.localStorage){
            if(window.localStorage.hasOwnProperty(key)){
                allStrings += window.localStorage[key];
            }
        }
        return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';
};

// 2)
new Blob(Object.values(localStorage)).size;

// 3) 
var _lsTotal=0,_xLen,_x;for(_x in localStorage){ if(!localStorage.hasOwnProperty(_x)){continue;} _xLen= ((localStorage[_x].length + _x.length)* 2);_lsTotal+=_xLen; console.log(_x.substr(0,50)+" = "+ (_xLen/1024).toFixed(2)+" KB")};console.log("Total = " + (_lsTotal / 1024).toFixed(2) + " KB");

// See more examples and read more here: 
Comment

PREVIOUS NEXT
Code Example
Javascript :: slice array of objects javascript 
Javascript :: react table className 
Javascript :: node js code for saving first middle and last name 
Javascript :: react particles js 
Javascript :: Remove an item by index position 
Javascript :: javascript detect if the browser tab is active 
Javascript :: HSET in redis 
Javascript :: js round floar 
Javascript :: what is express static 
Javascript :: exponential javascript 
Javascript :: javascript select2 sortable 
Javascript :: Alpine.js: button using @click function not working 
Javascript :: sum array elements in javascript 
Javascript :: react event for modals 
Javascript :: send sms with twilio 
Javascript :: javascript forloop 
Javascript :: react pdf 
Javascript :: using plice to remove an element from an array in react 
Javascript :: check cookies client side 
Javascript :: react js and graphql integration 
Javascript :: Each then() should return a value or throw 
Javascript :: req.params 
Javascript :: postman environment variable 
Javascript :: basic json syntax 
Javascript :: eval in javascript 
Javascript :: regex number 
Javascript :: flightphp 
Javascript :: invertir un array javascript 
Javascript :: how to compare two strings in javascript if condition 
Javascript :: set state using object 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =