zoukankan      html  css  js  c++  java
  • Set和Map数据结构

    1. Set容器 : 无序不可重复的多个value的集合体

      * Set()

      * Set(array)

      * add(value)

      * delete(value)

      * has(value)

      * clear()

      * size

    2. Map容器 : 无序的 key不重复的多个key-value的集合体

      * Map()

      * Map(array)

      * set(key, value)//添加

      * get(key)

      * delete(key)

      * has(key)

      * clear()

      * size

      let set = new Set([1,2,3,4,3,2,1,6]);
        console.log(set);
        set.add('abc');
        console.log(set, set.size);
        //delete(value)
        set.delete(2);
        console.log(set);
        //has(value)
        console.log(set.has(2));//false
        console.log(set.has(1));//true
        //clear()
        set.clear();
        console.log(set);
    
        let map = new Map([['abc', 12],[25, 'age']]);
        console.log(map);
        map.set('男', '性别');
        console.log(map);
        console.log(map.get(25));//age
        //delete(key)
        map.delete('男');
        console.log(map);
        console.log(map.has('男'));//false
        console.log(map.has('abc'));//true
        map.clear();
    console.log(map);

    3:for of循环

    for(let value of target){}循环遍历

      1. 遍历数组

      2. 遍历Set

      3. 遍历Map

      4. 遍历字符串

      5. 遍历伪数组

     let arr = [1,2,3,4,5];
        for(let num of arr){
            console.log(num);
        }
        let set = new Set([1,2,3,4,5]);
        for(let num of set){
            console.log(num);
        }
        let str = 'abcdefg';
        for(let num of str){
            console.log(num);
        }
        let btns = document.getElementsByTagName('button');
        for(let btn of btns){
            console.log(btn.innerHTML);
    }
    

      

    4:

    1. 指数运算符(幂): **

    2. Array.prototype.includes(value) : 判断数组中是否包含指定value

     

  • 相关阅读:
    spring MVC配置详解
    使用JDBC连接各种数据库
    Linux Shell常用shell命令
    IOS返回go(-1)
    NFS客户端挂载
    oracle常用函数
    支付宝手机网站支付流程(Node实现)
    SQL中的case when then else end用法
    mysql
    socket
  • 原文地址:https://www.cnblogs.com/love-life-insist/p/9938800.html
Copyright © 2011-2022 走看看