ES6_12_Set和Map数据结构以及for of循环

Set数据结构:

# Set容器 : 无序不可重复的多个value的集合体
* Set()
* Set(array)
* add(value)
* delete(value)
* has(value)
* clear()
* size

set容器:

//set容器
    let set = new Set([1,2,4,5,2,3,6]);
    console.log(set);//[[Entries]]: Array(6) 0: 1、1: 2、2: 4、3: 5、4: 3、5: 6 length: 6
    set.add(7);
    console.log(set.size,set);//length:7
    console.log(set.has(8));//false
    console.log(set.has(7));//true
    set.clear();
    console.log(set);

Map数据结构:

# Map容器 : 无序的 key不重复的多个key-value的集合体
* Map()
* Map(array)
* set(key, value)//添加
* get(key)
* delete(key)
* has(key)
* clear()
* size

map容器:

//map容器
    let map = new Map([['aaa', 'username',25],[36,'age']]);
    //let map = new Map([{key:'kobe'}]);
    console.log(map);
    map.set(78,'yingyingying');
    console.log(map);
    map.delete(36);
    console.log(map);

for_of循环:

for(let value of target){}循环遍历
1. 遍历数组
2. 遍历Set
3. 遍历Map
4. 遍历字符串
5. 遍历伪数组

用法举例:

//for of 用法详解
    let arr = [1,2,4,5,5,6,2];
    let arr1 = arr;
    arr = [];
    let set = new Set (arr1);
    for(let i of set){
        arr.push(i)
    }
    console.log(arr);
我是一个刚刚开始写博客的大可,内容有不详细或是错误的,还希望各位大佬私信我,我会进行纠正,谢谢啦!^-^
原文地址:https://www.cnblogs.com/sunjiaojiao/p/11153490.html