Learning JavaScript Data Structures and Algorithms
上QQ阅读APP看书,第一时间看更新

Iterating using the for...of loop

You have learned that we can iterate an array using the for loop and the forEach method. ES2015 introduced the for..of loop, which iterates through the values of an array. We can take a look at an example of how to use the for..of loop:

for (const n of numbers) { 
  console.log(n % 2 === 0 ? 'even' : 'odd'); 
}