es6 Set的几种使用场景
生活随笔
收集整理的這篇文章主要介紹了
es6 Set的几种使用场景
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// 數組去重let arr = [1, 1, 2, 3];let unique = [... new Set(arr)];let a = new Set([1, 2, 3]);let b = new Set([4, 3, 2]);// 并集let union = [...new Set([...a, ...b])];// 交集let intersect = [...new Set([...a].filter(x => b.has(x)))];// 差集let difference = Array.from(new Set([...a].filter(x => !b.has(x))));
總結
以上是生活随笔為你收集整理的es6 Set的几种使用场景的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: React Native组件开发指南
- 下一篇: python 解码json数据并在一个O