I am making a local login using JavaScript and I need to know the fastest way to scan an array.
Say there are two arrays:
usernames = ["uname 1", "uname 2", "uname 3"];
passwords = ["pswd 1", "pswd 2", "pswd 3"];
And there are two HTML inputs
<input id="username">
<input id="password">
I need to know the fastest way to see if the value from the HTML inputs matches any username and password.
I have tried a while function:
while(counter1 < usernames.length){
//testing goes here
counter ++;
}
And an "if / repeate" function
if(counter1 < usernames.length){
//testing goes here
setTimeout(currentFunction, 1);
}
This is not a duplicate of the question "What's the fastest way to loop through an array in JavaScript?" because I am open to more than a
for
loop
For "the fastest" to matter, I assume there must be a lot of entries in the array — like, millions. If so, I'd definitely offload to native code by using Array#indexOf
or Array#includes
(if all you need to know is whether there's a match). Otherwise, really, it doesn't matter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.