首页 > 代码库 > [ES6] 17. Set
[ES6] 17. Set
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。