ES6 has added some new tricks including iteration protocols. You may want to take a look at Iteration Protocols on MDN to get a tighter grasp on how to utilize them. for(item in array)
is still around, but you can use the new for ... of
on certain things.
Considering your code:
var x = new Set
x.add(1)
x.add(2)
x.values()
Let us say that, where var y = x.values();
, y
is an iterator;
In order to iterate over said iterator, you use a for(let item of iterable){}
loop. In this instance, you would be using:
for(let z of x){
console.log(z);
}
Which would print out:
1
2