javascript - Print all the names of keys stored in localStorage html -
this question has answer here:
- get html5 localstorage keys 8 answers
i'm trying print names of keys stored in localstorage each key in separate line. code:
function viewsaved(){ $('#saved').show(); var stuffsaved = object.keys(localstorage); var splitit = stuffsaved.split(','); (var = 0 ; < splitit.length ; i++ ){ $('#saved').append(splitit[i]+"<br>"); } }
when call function, nothing.
how do properly?
object.keys
returns array, not string. modify slightly:
var stuffsaved = object.keys(localstorage); (var = 0 ; < stuffsaved.length ; i++ ) { $('#saved').append(stuffsaved[i]+"<br>"); }
if have or expect lot of keys, suggest building list in temporary variable first avoid frequent dom update, example:
var keys = object.keys(localstorage); var list = ""; (var = 0 ; < keys.length ; i++ ) { list += keys[i] + "<br>"; } $('#saved').append(list);
Comments
Post a Comment