- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Iterables
JavaScript Generators & Iterators
JavaScript Iterables
An iterable is anything with a Symbol.iterator method, which is what for...of actually looks for.
An iterable is anything with a
Symbol.iteratormethod, which is whatfor ofactually looks for.
Iterable and iterator sound alike but mean different things.
An iterable knows how to produce an iterator; the iterator does the actual work.
Example
Example
javascript
const numbers = [1, 2, 3];
console.log(typeof numbers[Symbol.iterator]);
for (const n of numbers) {
console.log(n);
}