Which fix removes the bug?
const nums = [10, 20, 30];
for (const i in nums) {
console.log(i * 2);
}
- Use
for (const n of nums)to get values - Use
for (const i on nums)to get values - Change
i * 2toi + iin the body - Change
const itolet iin the header
for...in yields string keys ('0','1'), so the multiply is wrong; for...of yields the values.