更新时间:2022-11-13 22:25:53
要查找数组的实例,请使用:
To find an instance of an array use:
users.find(x => x.username == value);
这将返回 USER 数组中具有匹配用户名的对象.如果它不存在,它将返回 undefined.
This will return the object in the USER array that with the matching user name. It will return undefined if it doesn't exist.
您也可以使用 findIndex
,它将返回数组中与谓词匹配的项目的索引,如果不存在则返回 -1:
You can also use findIndex
, which will return the index of the item in the array that matches the predicate or -1 if it doesn't exist:
users.findIndex(x => x.username == value);
至于拥有用户名和密码列表,这绝对不是推荐的身份验证.我希望您正在为生产应用程序做其他事情.
As for having a list of usernames and passwords, this is definitely not recommended authentication. I hope you are doing something else for a production application.