1
I’m studying vectors and I used cars and parking spaces for example.
But the console.log
starts from the 0
and I wanted him to tell from the 1
and even so present 4 vacancies "1, 2 , 3, 4".
Code:
let vagas = ['Audi', 'HB20', 'Lamborghini', 'Maserati']
console.log(`No estacionamento tem ${vagas.length} vagas`)
for (let lugar in vagas) {
console.log(`na vaga ${lugar} está o Automóvel ${vagas[lugar]}`)
}
The exit follows:
na vaga 0 está o Automóvel Audi
na vaga 1 está o Automóvel HB20
na vaga 2 está o Automóvel Lamborghini
na vaga 3 está o Automóvel Maserati
I wanted it to count "1 ,2 ,3 ,4".
PS: for...in should not be used for iteration in an array where the order is important, since it iterates it in an arbitrary order - fountain: MDN Web Docs | for...in
– Augusto Vasques