在线文档教程

set.@@iterator

set.@@iterator

@@iterator属性的初始值与values属性的初始值是相同的函数对象。

句法

mySet[Symbol.iterator]

返回值

Set 迭代器功能,这是values()默认功能。

例子

运用 [@@iterator]()

var mySet = new Set( mySet.add('0' mySet.add(1 mySet.add{} var setIter = mySet[Symbol.iterator]( console.log(setIter.next().value // "0" console.log(setIter.next().value // 1 console.log(setIter.next().value // Object

使用[@@iterator]()与for..of

var mySet = new Set( mySet.add('0' mySet.add(1 mySet.add{} for (var v of mySet) { console.log(v }

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Set.prototype@@iterator' in that specification.StandardInitial definition.
ECMAScript 2017 Draft (ECMA-262)The definition of 'Set.prototype@@iterator' in that specification.Draft

浏览器兼容性

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support(Yes)36 (36) 1No supportNo supportNo support

FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support(Yes)(Yes)36.0 (36) 1No supportNo supportNo support