码迷,mamicode.com
首页 > 其他好文 > 详细

[ES6] 17. Set

时间:2015-01-02 06:26:51      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

Es6 provides "Set", it likes array but the data inside should be unqiue.

"Set" is a construct function, you should call:

var s = new Set();

 

Methods:


 

1. add(value)

[2,3,5,4,5,2,2].map(x =>s.add(x) )
for(num of s){
 console.log(num);   
}

//2, 3, 5, 4

 

2. delete(value)

[2,3,5,4,5,2,2].map(x =>s.add(x) );

s.delete("3");

for(num of s){
 console.log(num);   
}

//2, 5, 4

 

3. has(value)

[2,3,5,4,5,2,2].map(x =>s.add(x) );

s.delete("3");

for(num of s){
 console.log(num);   
}

s.has("3"); //false

 

4. size()

[2,3,5,4,5,2,2].map(x =>s.add(x) )
for(num of s){
 console.log(num);   
}

s.size(); // 4

 

5. claer()

[2,3,5,4,5,2,2].map(x =>s.add(x) )
for(num of s){
 console.log(num);   
}

s.clear(); 
s.size(); // 0

 

[ES6] 17. Set

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4198106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!