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 September 2016.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

La valeur initiale de la propriété @@iterator correspond à la valeur initiale fournie par l'itérateur values.

Syntaxe

js
arr[Symbol.iterator]();

Valeur de retour

La première valeur fournie par values(). Si on utilise arr[Symbol.iterator] (sans les parenthèses) le navigateur renverra par défaut la fonction values().

Exemples

Parcourir un tableau avec une boucle for...of

js
var arr = ["w", "y", "k", "o", "p"];
var eArr = arr[Symbol.iterator]();
// il est nécessaire que l'environnement supporte
// les boucles for..of et les variables
// utilisées avec let ou const ou var
for (let letter of eArr) {
  console.log(letter);
}

Parcourir un tableau avec next

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

Spécifications

Specification
ECMAScript® 2026 Language Specification
# sec-array.prototype-%symbol.iterator%

Compatibilité des navigateurs

Voir aussi