I’m a beginner student and I’m try to get some information from “user” using the prompt() function, and then throw this information in an array. I need to use the loop FOR and the WHILE to solve this problem.
This is my code:
let allEmployeess = Number(prompt("How many employees in the company?"));
let employee = new Array(allEmployeess);
let contador = 1;
for (let i = 0; i <= employee.length; i++) {
let colaborador = {
name: prompt("Employee name:"),
salary: Number(prompt("What is the salary amount??"))
}
employee.unshift(colaborador);
}
This isn’t working and I’m falling into an infinite loop.
I suppose this happens because the unshift(and push) method, return the new lenght of the array, and maybe I’m increasing the array leaving it always bigger than the counter.
What can I do to solve this?