my code have issue will show both if and else alert when key in information in web.

If you look at this block here:

for (let i = 0; i < data.length; i++) {


    if (data[i].username === username && data[i].password === password) 
    {
      alert("good"); 
      break;
    } 
    else {
      alert("not this!!!!") 
    }
  }

Is that the code block you are referring to?

You can see that we are running that if-else block for each data item. However, we only break out of the for loop if we reached a match. Therefore, it will keep showing "not this!" until you hit the match. For example, suppose you enter username George and Pass3333. It will first try John, and say "not this!". Then it will try Mary, and say "not this!". Then it will try George and say "correct" and then break out of the loop and stop trying more usernames.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.