JavaScript Symbol.iterator Property
Symbol.iterator is the symbol used to make an object iterable. Define a method with this key and the object works with for...of and spread syntax.
Description
Symbol.iterator is a well-known symbol. An object becomes iterable when it has a method under this key that returns an iterator. Arrays, strings, maps and sets already have one, and that's what for...of, spread syntax, destructuring and Array.from() call. A generator function is the easiest way to write one.
The method must return an iterator: an object with a next() method that returns { value, done }. Defining it as a generator method, *[Symbol.iterator]() { ... }, creates that iterator for you. Each call should return a fresh iterator, so the object can be looped over more than once.
Symbol.asyncIterator is the asynchronous counterpart, used by for await...of. Checking typeof obj[Symbol.iterator] === 'function' is the standard way to test whether a value is iterable.
Syntax
Symbol.iteratorValue
A well-known symbol.
Example
Browser Support
The following information will show you the current browser support for the Symbol.iterator property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





