Set方法
Set的方法
size 查看Set集合元素个数 add 给Set集合添加新的元素对象 delete Set元素删除某个元素 has 检测Set集合是否有该元素 clear 清除Set所有元素
演示案例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let list = [0, 0, 1, 2, 3, 3, 2, 1];
let arr = new Set(list);
arr.add(4);
console.log(arr.has(3));
arr.delete(3);
console.log(arr);
console.log(arr.size);
</script>
</body>
</html>
Map
方法如下:
set 添加元素 size 获取Map对象key多少 delete 删除Map对象中的某个key get 获取键值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let obj = new Map();
let obj1 = {};
obj.set(obj1,"这是一个Map对象");
console.log(obj.get(obj1));
console.log(obj.delete(obj1));
console.log(obj.size);
</script>
</body>
</html>
|