Last active
December 30, 2015 17:49
-
-
Save rdpanek/7863269 to your computer and use it in GitHub Desktop.
Example 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
env = [ | |
{ | |
"name": "Výdaje", | |
"color": "#ffffff" | |
} | |
] | |
env_saved = localStorage['envelopes']; | |
if (env_saved !== undefined ) { | |
envelopes = JSON.parse(env_saved); | |
_env = [], e = [] | |
for (var i = 0; i < envelopes.length; i++) { | |
_env = | |
{ | |
"name": envelopes[i].name+"_add", | |
"color": envelopes[i].color | |
} | |
e.push(_env); | |
}; | |
e.push(env[0]); | |
localStorage['envelopes'] = JSON.stringify(e); | |
} else { | |
localStorage['envelopes'] = JSON.stringify(env); | |
} | |
console.log(localStorage['envelopes']) | |
var localStorageSpace = function() { | |
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)'; | |
}; | |
console.log(localStorageSpace()); | |
localStorage.removeItem('envelopes'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment