February 2018
Intermediate to advanced
298 pages
8h 22m
English
Until now, we have been iterating over an iterable object using the next() method, which is a cumbersome task. ES6 introduced the for…of loop to make this easier.
The for…of loop was introduced to iterate over the values of an iterable object. Here is an example to demonstrate this:
function* generator_function(){ yield 1; yield 2; yield 3; yield 4; yield 5;}let arr = [1, 2, 3];for(let value of generator_function()){ console.log(value);}for(let value of arr){ console.log(value);}
The output is as follows:
12345123
Read now
Unlock full access