map.@@iterator
map.@@iterator
@@iterator
属性的初始值与entries
属性的初始值是同一个函数对象.
语法
myMap[Symbol.iterator]
返回值
map的 iterator
函数默认就是entries()
函数,也就是说直接遍历myMap和遍历myMap.entries()是一样的效果
.
示例
使用 [@@iterator]()
var myMap = new Map(
myMap.set('0', 'foo'
myMap.set(1, 'bar'
myMap.set{}, 'baz'
var 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"]
在for..of中使用[@@iterator]()
var myMap = new Map(
myMap.set('0', 'foo'
myMap.set(1, 'bar'
myMap.set{}, 'baz'
for (var v of myMap) {
console.log(v
}
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Map.prototype@@iterator' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Map.prototype@@iterator' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | 36 (36) 1 | No support | No support | No support |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|
Basic support | No support | 36.0 (36) 1 | No support | No support | No support | (Yes) |