zoukankan      html  css  js  c++  java
  • [ES6] 17. Set

    Es6 provides "Set", it likes array but the data inside should be unqiue.

    "Set" is a construct function, you should call:

    var s = new Set();

    Methods:


    1. add(value)

    [2,3,5,4,5,2,2].map(x =>s.add(x) )
    for(num of s){
     console.log(num);   
    }
    
    //2, 3, 5, 4

    2. delete(value)

    [2,3,5,4,5,2,2].map(x =>s.add(x) );
    
    s.delete("3");
    
    for(num of s){
     console.log(num);   
    }
    
    //2, 5, 4

    3. has(value)

    [2,3,5,4,5,2,2].map(x =>s.add(x) );
    
    s.delete("3");
    
    for(num of s){
     console.log(num);   
    }
    
    s.has("3"); //false

    4. size()

    [2,3,5,4,5,2,2].map(x =>s.add(x) )
    for(num of s){
     console.log(num);   
    }
    
    s.size(); // 4

    5. claer()

    [2,3,5,4,5,2,2].map(x =>s.add(x) )
    for(num of s){
     console.log(num);   
    }
    
    s.clear(); 
    s.size(); // 0
  • 相关阅读:
    docker命令总结
    VulToEs
    MYSQL
    MoonStack
    Spring mvc json null
    MySQL
    极光推送
    坑爹的RockSaw和坑爹的windows7
    App接口设计思路
    CSUOJ 1329 一行盒子(数组模拟链表)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4198106.html
Copyright © 2011-2022 走看看