Set: collection

Set: set
1. How to create a set target?
The let set = new new the SET ([4,3,2,3,3,2,1,3,3,2,5]);
2. attributes:
size: length,
the Set new new SET = the let ([4,3,2,3,3,2,1,3,3,2,5]);
the console.log (SET);
the console.log (set.size);
3. method :
1. the Add (): set to the element object is added,
the let set the Set new new = ();
set.add (. 1) .add (2) .add (. 3) .add (. 4) .add (. 5) .add ( '. 1') the Add ({}) the Add ({});..
the console.log (set);
2. delete (): delete the specified set of object elements,
3. has (): determines whether there is currently set specified element, returns a Boolean value,
4. Clear (): empty set target
4. how to traverse the object set
1. for (variable names set of) {}
2. Keys (): Get the collection of all the Key,
for (the let of set.keys Key ()) {
the console.log ( "Keys:" Key +);
}
3. values (): Get all set value,
for(let value of set.values()){
console.log(‘values:’ + value);
}
4. entries() : 获取集合中所有的key和value,
for(let [key,value] of set.entries()){
console.log(key + ‘=>’ + value);
}
5. forEach(function(value,key,set){})
set.forEach(function(value,key,set){
console.log(key,value,set);
})

Guess you like

Origin blog.csdn.net/weixin_45052104/article/details/90926944