Array.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 May 2018.
Сводка
Начальное значение свойства @@iterator
является тем же самым функциональным объектом, что и начальное значение, возвращаемое методом values()
.
Синтаксис
arr[Symbol.iterator]()
Примеры
Пример: итерация посредством цикла for...of
js
var arr = ["w", "y", "k", "o", "p"];
// ваш браузер должен поддерживать цикл for..of
// и переменные с областью видимости let в циклах for
for (let letter of arr) {
console.log(letter);
}
Пример: альтернативный способ итерации
js
var arr = ["w", "y", "k", "o", "p"];
var eArr = arr[Symbol.iterator]();
console.log(eArr.next().value); // w
console.log(eArr.next().value); // y
console.log(eArr.next().value); // k
console.log(eArr.next().value); // o
console.log(eArr.next().value); // p
Спецификации
Specification |
---|
ECMAScript® 2025 Language Specification # sec-array.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.