javascript - How do I get the key value when retrieving local storage -
i using html5 , local storage set / retrieve key/value pairs.
to set value:
localstorage.setitem("003o000000btrxz", "myvalue");
then utilized function loop through stored items
for(var = 0; < localstorage.length; i++) { var obj = localstorage.getitem(localstorage.key(i)); alert(obj); }
the result "myvalue" , "003o000000btrxz".
what proper syntax this?
use localstorage.key(i)
key:
for (var = 0; < localstorage.length; i++) { var key = localstorage.key(i); var value = localstorage.getitem(key); alert(key + ": " + value); }
javascript local-storage
No comments:
Post a Comment