I find this example and I was surprising the way that the eventually values of the generator are get from the generator. This is the code:
function* foo() {
yield 'a';
yield 'b';
yield 'c';
}
const [...values] = foo();
Based on my understand of generators, i think that destructuring a generator execution is equivalent to:
const array = [];
for(const val of foo()) {
array.push(val)
}
so, my question is: It is this a valid approach to get the values of a generator function and what other ways exists for achieve this?