There are 4 ways of array iteration:There are 4 ways of array iteration:
// 1: for
for (let i = 0; i < arr.length; ++i) {
console.log(arr[i]);
}
// 2: forEach
arr.forEach((v, i) => console.log(v));
// 3: for in
for (let i in arr) {
console.log(arr[i]);
}
// 4: for of
for (const v of arr) {
console.log(v);
}
SummarySummary: 1 and 3 solutions create extra variable, 2 - create extra function context. The best way is 4th - "for of"The best way is 4th - "for of".