๐Ÿ”ฐmake iterator iterable

JSโŸฉ iteration โŸฉ iterator โŸฉ make iterator iterable

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?