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'); 
} 

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.