首页 > 其他 > 详细

五、es6 Set

时间:2018-11-28 21:20:21      阅读:152      评论:0      收藏:0      [点我收藏+]

一、特点

1.是一个构造函数

2.类数组,元素唯一、没有重复

二、new Set();

技术分享图片

二、构造函数接受数组将数组转换成Set数据结构,[...new Set(1,3)],转化成对象;

console.log([...new Set([1,2,3])]);
let s = new Set([1,2,3,2]);
console.log(s.size); // 3
s.add(5);
console.log(s); // Set { 1, 2, 3, 5 }
s.delete(3);
console.log(s); // Set { 1, 2, 5 }
console.log(s.has(2)); // true
console.log(s.clear()) // undefined
console.log(s); // Set {}
s.add(1).add(2).add(2);
console.log(s); // Set { 1, 2 }

 

console.dir(Set)

技术分享图片

 

五、es6 Set

原文:https://www.cnblogs.com/shangyueyue/p/10034302.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!