const cars = ['BMW', 'Volvo', 'Saab', 'Ford', 'Fiat', 'Audi'];
const arr = [];
for (let i = 0; i < cars.length; i++) {
const i = 'hi';
console.log(i);
}
the result of this code would be:
hi
hi
hi
hi
hi
hi
how can I save this result to a variable as an array?
The returned value should be: ['hi','hi','hi','hi','hi','hi']
arr.push(i)to the loop.iinside the loop with the same name as the loop counter? What if you needed the value of the loop counter inside the loop?(new Array(cars.length)).fill('hi')