JS loop only works when matching to the last element in an array
<p>I cannot get the loop to work in my simple js login script. When i try to login with any login other than the last one in the array (user3 and pass3) it returns false.</p>

<p>What am I doing wrong?</p>

<p>I have tried both <code>==</code> and <code>===</code>.</p>

<pre><code>var userLogins = [{user:"user1", password:"pass1"},{user:"user2", password:"pass2"},{user:"user3", password:"pass3"}]
var success = null;
function logon(user, pass) {
    userok = false;
    for (i = 0; i &lt; userLogins.length; i++)
    { 
        if(pass == userLogins[i].password &amp;&amp; user == userLogins[i].user )
        {
            success = true;
        }
        else
        {
            success = false;
        }
    }
    secret(success);
}

function getData() {
    var user = document.getElementById("userid").value;
    var password = document.getElementById("password").value;
    logon(user, password);
}

function secret(auth){
    if(auth)
    {
        show('success');
        hide('login');
    }
    else
    {
        show('error');
        hide('login');
    }
}

function show(show) {
    document.getElementById(show).className = "show";
}
function hide(hide) {
    document.getElementById(hide).className = "hide";
}
</code></pre>

<p></p>
