当前位置:网站首页>Basic usage of set, map, DOM classlist in ES6
Basic usage of set, map, DOM classlist in ES6
2022-07-26 02:00:00 【Bald mule】
Catalog
1.set Define and initialize data
3.delete Deletes the specified element
4.has Query the specified element
2.delete Deletes the specified element
3.size obtain map The length of has Get the specified element
3、 ... and 、DOM classList Basic usage
One 、set Basic usage
It's like an array , But the values of the members are unique , There are no duplicate values . It's like an array , But the values of the members are unique , There are no duplicate values .
1.set Define and initialize data
const set = new Set([1,2,3,4,4]);
console.log(set);// Will automatically delete the duplicate 1,2,3,42.add add to
const set = new Set([1,2,3,4,4]);
set.add(5).add(6);
console.log(set);//1,2,3,4,5,63.delete Deletes the specified element
const set = new Set([1,2,3,4,4]);
set.add(5).add(6);
set.delete(6);
console.log(set);//1,2,3,4,5,4.has Query the specified element
const set = new Set([1,2,3,4,4]);
set.add(5).add(6);
set.delete(6);
console.log(set.has(6));//false5.clear Delete all
const set = new Set([1,2,3,4,4]);
set .clear();
console.log(set);//set(0)Two 、map data structure
1.set get Basic usage
const Info = {height:190,major:" Computer "};
const map = new Map();
// Set up map Value key->value
map.set("realname"," Zhang San ");
map.set("age",18);
map.set(Info," Personal details ");
//get obtain map Value Parameters :key
console.log(map.get("realname"));2.delete Deletes the specified element
// Delete map Value Parameters :key
map.delete("age");3.size obtain map The length of has Get the specified element
// obtain map The length of
console.log(map.size);
console.log("age Whether there is :" + map.has("age"));//falase Above to delete 4. obtain map All of key
const keys = map.keys();
console.log(keys);5.clear Delete
map.clear();3、 ... and 、DOM classList Basic usage
1. Complete code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.class1{
background: red;
}
.class2{
color:#fff;
}
.class3{
font-size: 20px;
}
</style>
</head>
<body>
<div id="demo"> I am a container </div>
<button id="btn1"> Control the color </button>
<button id="btn2"> Control font size </button>
<button id="btn3"> Determine whether there is a color style </button>
<button id="btn4"> Judging index 1 The name of the class </button><br/>
<button id="btn5"> Delete color style </button>
<button id="btn6"> Control font toggle The way </button>
<script>
let Demo = document.getElementById("demo");
let btn1 = document.getElementById("btn1");
let btn2 = document.getElementById("btn2");
let btn3 = document.getElementById("btn3");
btn1.addEventListener('click',()=>{
//classlist Add multiple styles
Demo.classList.add("class1","class2");
});
btn2.addEventListener('click',()=>{
Demo.classList.add("class3")
});
// classList.contains Determine whether there is a certain style
btn3.addEventListener('click',()=>{
console.log(Demo.classList.contains("class1")?" There is class1 The style of ":" non-existent class1 The style of ");
});
// classList.item Determine the class name of the specified subscript
btn4.addEventListener('click',()=>{
console.log(Demo.classList.item(1));
});
// classList.remove Delete style
btn5.addEventListener('click',()=>{
Demo.classList.remove("class1","class2");
});
btn6.addEventListener('click',()=>{
Demo.classList.toggle("class3");
// The second parameter Whether the style exists or not true Just force it false Force removal
Demo.classList.toggle("class3",false);
});
</script>
</body>
</html>2. Effect display

边栏推荐
- 2022 love analysis ― bank digitalization practice report
- Turn: do the right thing efficiently
- 在Anaconda 中安装和使用R
- SQL手工盲注、报错注入
- 推荐系统-协同过滤在Spark中的实现
- Protect syslog servers and devices
- AttributeError: ‘Document‘ object has no attribute ‘pageCount‘
- Proto conversion dart | project uses protobuf | fluent uses grpc
- 劳驾问一下各位老师 oracle 到pg cdc oracle 那边字段大写 pg 这边小写 同
- Shell exercises
猜你喜欢
![[Verilog digital system design (Xia Yuwen) 4 ----- basic concepts of Verilog syntax 2]](/img/fe/746ecaf4123072cca59d7510e9796c.png)
[Verilog digital system design (Xia Yuwen) 4 ----- basic concepts of Verilog syntax 2]

Silicon Valley classroom - official account cloud on demand Silicon Valley classroom microservice project practical notes
![[independent station construction] Shopify seller: learn these points and double the sales volume of online stores!](/img/52/8c1520db38ffa8927e975b6f244a65.png)
[independent station construction] Shopify seller: learn these points and double the sales volume of online stores!

AutoCAD -- Method of calculating area

What is cross site scripting (XSS)?

How idea can quickly delete recently opened projects

mysql 事务隔离级别

SQLyog数据导入导出图文教程

QT program beautification of the use of style sheets, QT uses pictures as the background and transparency of controls, QT custom button styles

pt-onnx-ncnn转换的问题记录(接yolov5训练)
随机推荐
How idea can quickly delete recently opened projects
Create a future and enjoy extraordinary | gbase Nantah General Motors unveiled opengauss Developer Day 2022
leetcode/只出现一次的数字
SVN version control branch and merge function use
还在用==0 null equal 判断空值吗,对isEmpty 和 isBlank有多少了解呢
Leetcode/ numbers that appear only once
Study notes: original code, inverse code, complement code
Alibaba cloud redis development specification
Zhinai buys melons (DP backpack)
Arm assembly foundation of SOC
[leetcode] 32. Longest valid bracket
npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
Redis6.x配置参数详解
重发布基础与配置
Software group verification
我mysql to mysql数据表同步,代码上只有写在第一个顺序上的生效 其余的不生效,这个可能是
[independent station construction] Shopify seller: learn these points and double the sales volume of online stores!
Image batch processing Gaussian filter noise reduction + peak signal-to-noise ratio calculation
怎么使用宝塔面板把node全栈项目部署到服务器上
登堂入室soc之编程基础环境变量设置