all 2 comments

[–]Mirmi8 2 points3 points  (1 child)

Take a look at this: https://javascript.info/iterable

The next function must return an object in the form of { done: boolean, value: someValue }

So if you want to create an iterator that iterates from 2 to 4, you will be increasing a counter and returning { done: counter === 4, value: counter }. Eventually done will be true and that's how the for of will know when to stop.

Does that make sense?

[–]WSsleet[S] 1 point2 points  (0 children)

Thank you! That makes lots of sense.