1: the set
It’s like an array, but its members are unique which means that as long as you have an object, you don’t accept another object, everything inside of it is unique
const s=new Set(a); s.add(1).add(2).add(3).add(2);
/ / "1.2.3"
Copy the code
Perform array de-duplication
var arr2=[1.23.3.12.. 57.23.6.1.]
var arr3=[..new Set(arr2)] [..xx]es6 extension operator, conversion arrayCopy the code
2: the map
It’s like an object, it exists as key-value pairs, but its keys can be of any type. It’s like a person, his object can be like, same sex, opposite sex, different race, ah, across all kinds of love
const m=new Map(a); m.set('name'.'value')
m.set('name'.'amy'). ('age'.'18')
Copy the code
New for of traversal available in ES6
for(let[key,value]of m){
}
Copy the code
It can be used as a message board or something. It’s very convenient
$(funtion(){
// Submit a message
const m=new Map(a); $(".submit").click(() = >{
let _name=$(".. name").val();
_msg=$(".message").val();
m.set(' _name'.'_msg');
listShow();
});
// Display messages
let listShow=() = >{
let str=""
for(let[key,value]of m){
str+=`<li class="list">${key}< span > said: < / span >${value}</li>`
}
$(".messageList").html(str); }})Copy the code
Ps: Set and map are both objects