Javascript Set union operation
function unionSet(setA, setB) { var union = new Set(setA); for (var elem of setB) { union.add(elem);//from w w w. ja v a2s . c o m } return union; } var setA = new Set([1, 2, 3, 4]), setB = new Set([2, 3]), setC = new Set([5]); let a = unionSet(setA, setB); console.log(a); let b = unionSet(setA, setC); console.log(b);