0

My code is not working for multiple users, how can i change my code?

 for(var i=0; i<=localStorage.length; i++){
        save.onclick = function(){
                var firstName = document.getElementById("fname").value;
                var number = document.getElementById("number").value;
                var email = document.getElementById("mId").value;

                localStorage.setItem('is_firstName', firstName);
                localStorage.setItem('is_number', number);
                localStorage.setItem('is_email', email);
        }}
student
  • 1
  • 1
  • 2
    `i <= localStorage.length` is a classic [off-by-one error](/q/2939869/4642212). You never use `i`, and keep overwriting `save.onclick`. It’s as if you can simply remove the loop. See also [JavaScript closure inside loops – simple practical example](/q/750486/4642212). – Sebastian Simon Nov 20 '22 at 17:32

0 Answers0