String.prototype[@@iterator]()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Сводка
Метод [@@iterator]()
возвращает новый объект итератора Iterator
, который проходит по кодовым точкам строкового значения, возвращая каждую кодовую точку в виде строкового значения.
Синтаксис
string[Symbol.iterator]
Примеры
Пример: использование метода [@@iterator]()
js
var string = "A\uD835\uDC68";
var strIter = string[Symbol.iterator]();
console.log(strIter.next().value); // "A"
console.log(strIter.next().value); // "\uD835\uDC68"
Пример: использование метода [@@iterator]()
вместе с циклом for..of
js
var string = "A\uD835\uDC68B\uD835\uDC69C\uD835\uDC6A";
for (var v of string) {
console.log(v);
}
// "A"
// "\uD835\uDC68"
// "B"
// "\uD835\uDC69"
// "C"
// "\uD835\uDC6A"
Спецификации
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype-%symbol.iterator% |
Совместимость с браузерами
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
[Symbol.iterator] |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Uses a non-standard name.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.