From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Iterating with the for/of loop

Iterating with the for/of loop - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Iterating with the for/of loop

- [Instructor] For/of is a new iteration syntax that we can use to replace for in and for each. Now, we can use this to loop over iterable objects, like arrays, strings, maps and sets. So let's go ahead and loop over a string. So we're going to say for and we'll say let letter of JavaScript and then for each letter in JavaScript, we'll log it to the console. So we see all of these different letters being added to the console on their own line. An array is also iterable. So we can create a variable called topics and set that equal to an array of JavaScript, Node and CSS. Now when we iterate over the topics, we can log each topic to the console. And we see all of them being added here at the bottom. So instead of using the array for topics, we're going to go ahead and create a new map and then we'll use the set function to define a key, which will be HTML. And a route where we can find more information about it. So…

Contents