javascript - Print all the names of keys stored in localStorage html -


this question has answer here:

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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -