What is the purpose of `Symbol.iterator` on an object?

JavaScript Professional Medium

JavaScript Professional — Medium

What is the purpose of `Symbol.iterator` on an object?

Key points

  • `Symbol.iterator` makes an object iterable for for...of loops
  • It allows the object to be spread using spread syntax
  • It enables destructuring of the object
  • Custom iterator is provided by `Symbol.iterator`

Ready to go further?

Related questions