遍历集合元素 [英] Iterate over set elements
问题描述
我为实验ECMAscript 6功能打开了Chrome标志,其中之一是 Set
.据我了解, Set
的详细信息已得到规范作者的广泛认可.
I have turned on the Chrome flag for experimental ECMAscript 6 features, one of which is Set
. As I understand, the details of Set
are broadly agreed upon by the spec writers.
我创建了一个 a
并添加了字符串'Hello'
I create a set a
and add the string 'Hello'
a = Set();
a.add('Hello');
但是我如何遍历 a
的元素?
but how do I iterate over the elements of a
?
for(let i of a) { console.log(i); }
给出"SyntaxError:扩展模式外的非法 let
声明"
gives "SyntaxError: Illegal let
declaration outside extended mode"
for(var i of a) { console.log(i); }
给出"SyntaxError:意外标识符"
gives "SyntaxError: Unexpected identifier"
for(var i in a) { console.log(i); }
给出未定义
是否有可能在浏览器26进行迭代的一组结束了吗?
Is it possible to iterate over of a set in Chrome 26?
推荐答案
操作符 Chrome当前似乎不受支持.似乎只有FireFox 13至18版本支持它.似乎也没有任何浏览器实际上支持 Set
,尽管该页面确实说某些测试表示存在而不是完整的功能或一致性.因此, Set
可能是在Chrome中部分实现的.
The of
operator doesn't appear to be currently supported in Chrome. It seems that only FireFox versions 13 through 18 support it. It also appears that none of the browsers actually support Set
although the page does say that some of the tests represent existence and not full functionality or coherence. So it might be that Set
is partially implemented in Chrome.
这篇关于遍历集合元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!