Web/JavaScript/Reference/Global objects/Map/@@iterator

From Get docs


The initial value of the @@iterator property is the same function object as the initial value of the entries method.


Syntax

myMap[Symbol.iterator]

Return value

The map iterator function, which is the entries() function by default.

Examples

Using [@@iterator]()

const myMap = new Map()
myMap.set('0', 'foo')
myMap.set(1, 'bar')
myMap.set({}, 'baz')

const mapIter = myMap[Symbol.iterator]()

console.log(mapIter.next().value) // ["0", "foo"]
console.log(mapIter.next().value) // [1, "bar"]
console.log(mapIter.next().value) // [Object, "baz"]

Using [@@iterator]() with for..of

const myMap = new Map()
myMap.set('0', 'foo')
myMap.set(1, 'bar')
myMap.set({}, 'baz')

for (const entry of myMap) {
  console.log(entry)
}
// ["0", "foo"]
// [1, "bar"]
// [{}, "baz"]

for (const [key, value] of myMap) {
  console.log(`${key}: ${value}`)
}
// 0: foo
// 1: bar
// [Object]: baz

Specifications

Specification
ECMAScript (ECMA-262)The definition of 'Map.prototype[@@iterator()' in that specification.]

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
@@iterator Chrome

Full support 43

Edge

Full support 12

Firefox Full support 36


Full support 36


No support 27 — 36

Notes' Alternate Name'

Notes' A placeholder property named @@iterator is used. Alternate Name' Uses the non-standard name: @@iterator No support 17 — 27

Notes' Alternate Name'

Notes' A placeholder property named iterator is used. Alternate Name' Uses the non-standard name: iterator

IE

No support No

Opera

Full support 30

Safari

Full support 10

WebView Android

Full support 43

Chrome Android

Full support 43

Firefox Android Full support 36


Full support 36


No support 27 — 36

Notes' Alternate Name'

Notes' A placeholder property named @@iterator is used. Alternate Name' Uses the non-standard name: @@iterator No support 17 — 27

Notes' Alternate Name'

Notes' A placeholder property named iterator is used. Alternate Name' Uses the non-standard name: iterator

Opera Android

Full support 30

Safari iOS

Full support 10

Samsung Internet Android

Full support 4.0

nodejs

Full support 0.12

Legend

Full support  
Full support
No support  
No support
See implementation notes.'
See implementation notes.
Uses a non-standard name.'
Uses a non-standard name.


See also