June 2016
Intermediate to advanced
910 pages
18h 59m
English
Until now, we were iterating over an iterable object using the next() method, which is a cumbersome task. ES6 introduced the for…of loop to make this task 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:
1 2 3 4 5 1 2 3
Read now
Unlock full access