Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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. 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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!