1

I am making a small login system using local storage. In my js I need some way to loop through the local storage to check if there is a match between the input form and json (username, password) in local storage.

Can I use a normal for loop ? jQuery .each?

Mac Luc
  • 971
  • 5
  • 14
  • 31

1 Answers1

1

Use Key to iterate in local db

for (var i = 0; i < localStorage.length; i++){
    console.log(localStorage.getItem(localStorage.key(i)));
}

and for keys :

for (var key in localStorage){
   console.log(key)
} 
Cerbrus
  • 70,800
  • 18
  • 132
  • 147
Bhupendra Shukla
  • 3,814
  • 6
  • 39
  • 62