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
  • 931
  • 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
  • 65,559
  • 18
  • 128
  • 140
Bhupendra Shukla
  • 3,766
  • 6
  • 36
  • 61