JavaScript String Symbol.iterator Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.prototype[Symbol.iterator]() returns an iterator that yields each Unicode code point as a string. That is what powers for...of, spread (...), and Array.from on strings (ES2015).

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Iterate a string. Start with this line.

JavaScript
str[Symbol.iterator]()
CallWhat it does
str[Symbol.iterator]()Primary signature.
str[Symbol.iterator](...)Call with the arguments your case needs.

Built into JavaScript. Strings are iterable via [Symbol.iterator]() β€” usually through for...of / spread.

Library declarations
JavaScript
str[Symbol.iterator]()

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*The value returned by str[Symbol.iterator]().

JavaScript Examples

Example 1 — for...of and Spread

The usual way to walk a string by Unicode code points.

JavaScript
const text = "Hi🌟";

for (const ch of text) {
  console.log(ch);
}
// H
// i
// 🌟

console.log(JSON.stringify([...text]));
// ["H","i","🌟"]
Try It Yourself

How It Works

  1. Iterable string. for...of calls [Symbol.iterator]() for you.
  2. One code point per step. ASCII letters and the emoji each yield once.
  3. Spread builds an array. [...text] collects every yielded value.
  4. No mutation. The original string is unchanged.

Example 2 — Manual next()

Call the iterator yourself when you need step-by-step control.

JavaScript
const it = "AB"[Symbol.iterator]();

console.log(it.next());
// { value: "A", done: false }

console.log(it.next());
// { value: "B", done: false }

console.log(it.next());
// { value: undefined, done: true }
Try It Yourself

How It Works

  1. Get an iterator. str[Symbol.iterator]() returns a fresh iterator object.
  2. Pull values. Each next() gives the next code point in value.
  3. Watch done. When finished, done is true and value is undefined.
  4. One-shot. Iterators are not rewindable β€” call [Symbol.iterator]() again to restart.

Example 3 — Iterator vs Indexing

Indexing reads UTF-16 units; the iterator yields full code points.

JavaScript
const text = "🌟";

console.log(text.length);              // 2  (UTF-16 units)
console.log(JSON.stringify([...text])); // ["🌟"]
console.log(JSON.stringify(text[0]));   // half of the surrogate pair
console.log(JSON.stringify([...text][0])); // "🌟"
Try It Yourself

How It Works

  1. Length counts units. Many emoji need two UTF-16 code units.
  2. Spread uses the iterator. You get one array item for the emoji.
  3. Index 0 is unsafe for emoji. It can return only half a surrogate pair.
  4. Rule of thumb. Prefer for...of / spread when β€œcharacters” mean code points.

Browser & Runtime Support

String.prototype[Symbol.iterator]() is part of ES2015 (ES6). It works in all modern browsers and Node.js versions in common use today.

✓ Baseline · ES2015

String[Symbol.iterator]()

Supported in Chrome 38+, Firefox 36+, Safari 9+, Edge 12+, and Node.js 4+. Not available in Internet Explorer without a polyfill.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
[Symbol.iterator] Excellent

Bottom line: Safe for modern web apps and current Node LTS. for...of and spread on strings require the same ES2015 iterator support.

Frequently Asked Questions

It returns a string iterator that yields each Unicode code point as a string. That makes strings iterable for for...of, spread (...), Array.from, and similar APIs.
Rarely. for...of and the spread syntax call it automatically. Call it manually when you want step-by-step control with next().
str[i] and charAt(i) read UTF-16 code units. The iterator yields full Unicode code points, so a single emoji made of a surrogate pair is one step, not two.
Surrogate pairs stay together as one code point. Grapheme clusters (emoji + skin tone, ZWJ sequences) can still split into multiple code points.
An object { value, done }. value is the next code-point string (or undefined when done is true).
No. It only creates an iterator that reads the string. Strings are immutable.

Next: includes()

Learn the boolean substring check β€” perfect for simple β€œcontains” tests.

includes() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P πŸ”—

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful