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.
La méthode [@@iterator]()
renvoie un nouvel objet Iterator
qui itère sur les points de code (codets) d'une chaîne de caractères, en renvoyant chaque point de code sous forme d'une chaîne de caractères.
Exemple interactif
Syntaxe
js
chaîneDeCaractères[Symbol.iterator];
Valeur de retour
Un nouvel objet Iterator
.
Exemples
Utiliser [@@iterator]()
js
var chaîne = "A\uD835\uDC68";
var chaîneIter = chaîne[Symbol.iterator]();
console.log(chaîneIter.next().value); // "A"
console.log(chaîneIter.next().value); // "\uD835\uDC68"
Utiliser [@@iterator]()
avec une boucle for..of
js
var chaine = "A\uD835\uDC68B\uD835\uDC69C\uD835\uDC6A";
for (var c of chaine) {
console.log(c);
}
// "A"
// "\uD835\uDC68"
// "B"
// "\uD835\uDC69"
// "C"
// "\uD835\uDC6A"
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype-%symbol.iterator% |
Compatibilité des navigateurs
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.