1 Star 2 Fork 0

周城乐/ES6

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
73-Set.html 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
周城乐 提交于 2022-05-19 00:24 +08:00 . ES6练习
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Set</title>
</head>
<body>
<script type="text/javascript">
const s1 = new Set();
console.log(s1.size);
const s2 = new Set(["a", "b"]);
console.log(s2.size);
//去重
const s3 = new Set(["a", "a", "b", "b"]);
console.log(s3.size);
const arr = [...s3];
console.log(arr);
const s4 = new Set();
// 向set结构中添加值 使用add方法
s4.add('a').add('b');
console.log(s4.size);
const arr1 = [...s4];
console.log(arr1);
// 从set结构中删除值 用到的方法是delete
const r1 = s4.delete('a');
console.log(s4.size);
console.log(r1);
// 判断某一个值是否是set数据结构中的成员 使用has
const r2 = s4.has('b');
console.log(r2);
// 清空set数据结构中的值 使用clear方法
s4.clear();
console.log(s4.size);
// 遍历set数据结构 从中取值
const s5 = new Set(['a', 'b', 'c']);
s5.forEach(value => {
console.log(value)
})
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhou-chengle/es6.git
[email protected]:zhou-chengle/es6.git
zhou-chengle
es6
ES6
master

搜索帮助