๐ฐmake iterator iterable
JSโฉ iteration โฉ iterator โฉ make iterator iterable
an iterator can be made iterable by making it return itself in the make-iterator method.
const iterator = {
// โญ๏ธ iterator must have `next()` method
next() {
// return iteration result ...
},
// โญ๏ธ iterable must have "make iterator" method
[Symbol.iterator] () {
// because `iterator` is itself an iterator,
// we can simply return itself. โญ๏ธ
return this;
},
};
Last updated
Was this helpful?