当前位置:网站首页>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

边栏推荐
- MPLS knowledge points
- AutoCAD -- Method of calculating area
- The detailed knowledge summary of MySQL can be collected
- Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington
- Image batch processing Gaussian filter noise reduction + peak signal-to-noise ratio calculation
- Create a future and enjoy extraordinary | gbase Nantah General Motors unveiled opengauss Developer Day 2022
- Alibaba cloud redis development specification
- How idea can quickly delete recently opened projects
- # Dest0g3 520迎新赛(更新中)
- Ti AM335X工控模块矩阵键盘电路的设计与驱动移植
猜你喜欢

BGP知识点总结
![Web3.0 blog DAPP development practice [2022]](/img/18/f386246ff6ffbd0a42df57c3cd9170.png)
Web3.0 blog DAPP development practice [2022]

SVN version control branch and merge function use

Worthington产气荚膜梭菌神经氨酸酶的特征及测定

AutoCAD -- Method of calculating area

SQL manual blind injection and error reporting injection

mysql 事务隔离级别

Digital transformation behind the reshaping growth of catering chain stores

Implementation of recommendation system collaborative filtering in spark

After reading this article, you should thoroughly understand how to do interface testing
随机推荐
Redis集群搭建(基于6.x)
BGP knowledge points summary
阿里云Redis开发规范
SQL手工盲注、报错注入
[Verilog digital system design (Xia Yuwen) 3 ----- basic concepts of Verilog syntax 1]
proto转换Dart | 项目使用Protobuf | flutter 使用grpc
My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
flink sql 如何配置打印insert实参日志呢
【独立站建设】shopify卖家:学会这几点,网上商店销量翻倍!
DialogRPT-Dialog Ranking Pretrained Transformers
Add an interceptor to resttemplate to record the request response, and you also need to solve the problem that the flow is read only once
FFT用于估计插值后的图像重采样因子
SVN version control branch and merge function use
推荐系统-协同过滤在Spark中的实现
E. Split into two sets
Zhinai buys melons (DP backpack)
leetcode/只出现一次的数字
How to do Taobao live broadcast and how to do the anchor to drain and sell products
After reading this article, you should thoroughly understand how to do interface testing
Implementation of C iterator