Hello I want to store username and password as an object in array. 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. 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