美文网首页
去重的hashset类似

去重的hashset类似

作者: 价值投机168 | 来源:发表于2021-03-05 14:10 被阅读0次

    mySet: Set<string> = new Set<string>();

    const mySet1 = new Set()

    mySet1.add(1) // Set [ 1 ]
    mySet1.add(5) // Set [ 1, 5 ]
    mySet1.add(5) // Set [ 1, 5 ]
    mySet1.add('some text') // Set [ 1, 5, 'some text' ]
    const o = {a: 1, b: 2}
    mySet1.add(o)

    mySet1.add({a: 1, b: 2}) // o is referencing a different object, so this is okay

    mySet1.has(1) // true
    mySet1.has(3) // false, since 3 has not been added to the set
    mySet1.has(5) // true
    mySet1.has(Math.sqrt(25)) // true
    mySet1.has('Some Text'.toLowerCase()) // true
    mySet1.has(o) // true

    mySet1.size // 5

    mySet1.delete(5) // removes 5 from the set
    mySet1.has(5) // false, 5 has been removed

    mySet1.size // 4, since we just removed one value

    console.log(mySet1)

    相关文章

      网友评论

          本文标题:去重的hashset类似

          本文链接:https://www.haomeiwen.com/subject/divrqltx.html