-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// map解决了js对象的键只能是字符串的问题 | ||
const m = new Map() | ||
const o = { name: 'object' } | ||
m.set(o, 1) | ||
m.get(o) | ||
|
||
console.log(m.has(o)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Set函数可以接受一个数组(或者具有 iterable 接口的其他数据结构)作为参数,用来初始化。 | ||
|
||
// let set = new Set() | ||
// let a = NaN | ||
// let b = NaN | ||
// set.add(a).add(b).add(1) | ||
// console.log(set) | ||
// console.log(set.size) | ||
// console.log(set.keys()) | ||
// console.log(set.values()) | ||
|
||
|
||
// 数组并集 | ||
let arr = [1, 2, 3, 4, 5] | ||
let arr2 = [3, 4, 5, 78, 9] | ||
console.log([...new Set([...arr, ...arr2])]) | ||
|
||
// 数组交集 | ||
console.log(arr.filter(item => new Set(arr2).has(item))) | ||
|
||
// WeakSet 只能存放对象 | ||
const ws = new WeakSet() | ||
ws.add({ a: 1 }) | ||
console.log(ws) |