简体   繁体   English

扫描JS数组的最快方法是什么?

[英]What is the fastest way to scan a JS array

I am making a local login using JavaScript and I need to know the fastest way to scan an array. 我正在使用JavaScript进行本地登录,我需要知道扫描数组的最快方法。

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 并且有两个HTML输入

<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. 我需要知道查看HTML输入中的值是否与任何用户名和密码匹配的最快方法。

I have tried a while function: 我试过一段时间的功能:

while(counter1 < usernames.length){
   //testing goes here
   counter ++;
}

And an "if / repeate" function 以及“if / repeate”功能

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?" 这不是“在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). 如果是这样,我肯定会使用Array#indexOfArray#includes卸载到本机代码(如果你需要知道的是是否匹配)。 Otherwise, really, it doesn't matter. 否则,真的,没关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在JS中找到路线的最快方法是什么? - What's the fastest way to find a route in JS? 在数组中使objectId唯一的最快方法是什么? - What is the fastest way to make objectIds unique in an Array? 用Javascript中的另一个数组替换数组的一部分的最快方法是什么? - What is the fastest way to replace a section of an array with another array in Javascript? 获取变量的所有初始值的最快方法是什么? JS - What's the fastest way to get all the initial values of a variable? JS 使用underscore.js对数组进行分类的最快方法是什么? - What is the fastest way to categorize arrays using underscore.js? 使用 JS 或 PHP 将 html 转换为 pdf 的最快方法是什么? - What is the fastest way to convert html to pdf using JS or PHP? JS显示列表的特定行的最快方法是什么? - JS What's the fastest way to display one specific line of a list? 在 JavaScript 中将 N 个未排序数组合并为 1 个排序数组的最快方法是什么? - What is the fastest way to merge N unsorted arrays into 1 sorted array in JavaScript? 用来自JavaScript数组的数据创建HTML表的最快方法是什么? - What is the fastest way to create HTML table with data from JavaScript array? 将递归 function 的结果连接到 Javascript 中的数组中的最快方法是什么? - What is the fastest way to concatenate results of a recursive function into an array in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM