Looping over localStorage items


/ Published in: JavaScript
Save to your folder(s)

The `localStorage.key` method is a great way to loop over localStorage items.


Copy this code and paste it in your HTML
  1. var i,
  2. ls = localStorage,
  3. l = ls.length,
  4. key;
  5.  
  6. for (var i = 0; i < l; i++) {
  7. key = ls.key(i);
  8. console.log(key + ": " + ls.getItem(key));
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.