标签:并集 去重 div str span nio new style 对象
数组去重,注意4 ‘4’ 不同
let arr = [1, 2, 3, 4, 4, ‘4‘, ‘4‘]; let mySet = new Set(arr); [...mySet]; // [1, 2, 3, 4, ‘4‘]
并集
let a = new Set([1, 2, 3]); let b = new Set([4, 3, 2]); let union = new Set([...a, ...b]); // {1, 2, 3, 4} [...union] // [1,2,3,4]
交集
let a = new Set([1, 2, 3]); let b = new Set([4, 3, 2]); let intersect = new Set([...a].filter(x => b.has(x))); // {2, 3} [...intersect] // [2,3]
差集
let a = new Set([1, 2, 3]); let b = new Set([4, 3, 2]); let difference = new Set([...a].filter(x => !b.has(x))); // {1} [...difference] // [1]
.
标签:并集 去重 div str span nio new style 对象
原文地址:https://www.cnblogs.com/xiangsj/p/14032308.html