Course contentsShow
← JavaScript
Lesson 2016 of 2,72342. Iteration Protocols Deep DiveFree lesson

Symbol.iterator on Built-ins

Arrays, strings, maps, sets, and typed arrays all implement Symbol.iterator natively.

Symbol.iterator on Built-ins

You'll learn which JavaScript data structures come with built-in iteration support out of the box.

The Pre-Built Iteration Family

Now that you understand how to create custom iterables, here's the good news: you don't need to implement Symbol.iterator for JavaScript's core data structures—they already have it!

Arrays, strings, Maps, Sets, and typed arrays all ship with native Symbol.iterator implementations. This means you can use for...of loops, spread syntax, and destructuring on them immediately without any setup.

Which Built-ins Are Iterable?

Here are the JavaScript built-ins that implement Symbol.iterator:

// Arrays
const arr = [1, 2, 3];
for (const num of arr) { /* works! */ }

// Strings
const str = "hello";
for (const char of str) { /* works! */ }

// Maps
const map = new Map([['a', 1], ['b', 2]]);
for (const [key, value] of map) { /* works! */ }

// Sets
const set = new Set([1, 2, 3]);
for (const item of set) { /* works! */ }

// Typed Arrays
const uint8 = new Uint8Array([10, 20, 30]);
for (const byte of uint8) { /* works! */ }

Each of these returns an iterator object when you access their Symbol.iterator property, making them fully compatible with the iteration protocol you've been learning.

Think of It Like Universal Plugs

It's like having appliances (arrays, strings, Maps, Sets) that all come with the same standard power plug—you don't need adapters or converters. The JavaScript language designed these core structures to work seamlessly with iteration from day one.

Key Takeaway: Arrays, strings, Maps, Sets, and typed arrays all implement Symbol.iterator natively, making them ready to use with any iteration-consuming syntax without additional work.