[英]How to take login credentials from user and push it in array as object in JavaScript?
Hello I want to store username and password as an object in array.您好,我想将用户名和密码存储为数组中的 object。 As of this time I have this code:到目前为止,我有这段代码:
var loginCred = [
{
username: "janhaxe23",
password: "HaxeJan23"
}];
function LogIn() {
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
for(i = 0; i < loginCred.length; i++) {
if(username == loginCred[i].username && password == loginCred[i].password) {
window.alert("Login Successfully. Welcome "+ username);
return;
}
}
window.alert("Incorrect login credentials. Please try again.");}
Instead of creating an object directly in JS file I want the user to input their login credentials by clicking the "Register" button.我希望用户通过单击“注册”按钮输入他们的登录凭据,而不是直接在 JS 文件中创建 object。 Thank you.谢谢你。
function register(){
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
loginCred.push({
username: username,
password: password
})
}
You can push values to an array like this您可以像这样将值推送到数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.