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

205
Views
java script function via 4 parameters

I am a beginner and new in java script. I have a problem and have tried some ways but problem is here. I wrote a function with 4 parameters and I want to get 4 arguments from input and save them to an array. It means every time gets 4 arguments and save them. this is my code but it is not working.

var personalInfo = {};

function addEmployee(firstName, lastName, hour, salary){
   personalInfo = personalInfo.push({'firstName':firstName, 'lastName':lastName, 'hour':hour, 'salary':salary});


return personalInfo;
}

addEmployee(personalInfo);

any solution would be my appreciate.

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

0

You need to change personalInfo to an array if you want to to push employees to an array. As also mentioned in the comments, you are only passing one parameter but you need to pass four parameters as shown in my example.

You also don't need to assign personalInfo when using push as this pushes a new object to the existing array.

var personalInfo = [];

function addEmployee(firstName, lastName, hour, salary){
   personalInfo.push({'firstName':firstName, 'lastName':lastName, 'hour':hour, 'salary':salary});

return personalInfo;
}

addEmployee('first Name', 'last Name', '11', '100');
addEmployee('first Name 2', 'last Name 2', '10', '40');
console.log(personalInfo);

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!