String.prototype[@@iterator]()

The [@@iterator]() method returns a new iterator object that iterates over the code points of a String value, returning each code point as a String value.

Syntax

str[Symbol.iterator]

Return value

A new iterator object.

Examples

Using [@@iterator]()

var str = 'A\uD835\uDC68';

var strIter = str[Symbol.iterator]();

console.log(strIter.next().value); // "A"
console.log(strIter.next().value); // "\uD835\uDC68"

Using [@@iterator]() with for..of

var str = 'A\uD835\uDC68B\uD835\uDC69C\uD835\uDC6A';

for (var v of str) {
  console.log(v);
}
// "A"
// "\uD835\uDC68"
// "B"
// "\uD835\uDC69"
// "C"
// "\uD835\uDC6A"

Specifications

Specification
ECMAScript Language Specification (ECMAScript)
# sec-string.prototype-@@iterator

Browser compatibility

BCD tables only load in the browser

See also