首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

map.@@iterator

@@iterator属性的初始值与entries属性的初始值是同一个函数对象.

语法

代码语言:javascript
复制
myMap[Symbol.iterator]

返回值

map的 iterator 函数默认就是entries()函数,也就是说直接遍历myMap和遍历myMap.entries()是一样的效果.

示例

使用 [@@iterator]()

代码语言:javascript
复制
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]()

代码语言:javascript
复制
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)

扫码关注腾讯云开发者

领取腾讯云代金券