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.
personalInfois an object and an object does not have.pushfunction.pushis available on an array only.addEmployee(personalInfo)- so why shouldlastName,hour, andsalaryexist inside your function now?personalInfois an object, not an array. And the first time you calladdEmployeeyou overwritepersonalInfowith a number (or you would if it didn't throw an exception because it isn't an array to start with).