Map.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 valeur initiale de la propriété @@iterator
est la même fonction que la valeur initiale de la propriété entries
.
Exemple interactif
const map1 = new Map();
map1.set("0", "foo");
map1.set(1, "bar");
const iterator1 = map1[Symbol.iterator]();
for (const item of iterator1) {
console.log(item);
}
// Expected output: Array ["0", "foo"]
// Expected output: Array [1, "bar"]
Syntaxe
js
maMap[Symbol.iterator];
Valeur de retour
La fonction d'itération (le symbole @@iterator
) de l'objet, par défaut, c'est la fonction entries()
.
Exemples
Utiliser [@@iterator]()
js
var maMap = new Map();
maMap.set("0", "toto");
maMap.set(1, "truc");
maMap.set({}, "bidule");
var mapIter = myMap[Symbol.iterator]();
console.log(mapIter.next().value); // ["0", "toto"]
console.log(mapIter.next().value); // [1, "truc"]
console.log(mapIter.next().value); // [Object, "bidule"]
Utiliser [@@iterator]()
avec for..of
js
var maMap = new Map();
maMap.set("0", "toto");
maMap.set(1, "truc");
maMap.set({}, "bidule");
for (var v of maMap) {
console.log(v);
}
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-map.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.