If you mean ES6 sets then you can do it simply:
function union(...sets) { return new Set([].concat(...sets.map(set => [...set]))); }
Then union(new Set([1, 2, 3]), new Set([3, 4, 5])); will return Set(4) {1, 2, 3, 4, 5}
If you need it to be done with ES5:
function unique(arr) { var result = []; for (var i = 0; i < arr.length; i++) { if (result.indexOf(arr[i]) === -1) { result.push(arr[i]); } } return result; } function union() { var result = []; for (var i = 0; i < arguments.length; i++) { result = result.concat(arguments[i]); } return unique(result); }
And usage will be
union([1, 2, 3], [3, 4, 5], [4, 5, 6]); // => [1, 2, 3, 4, 5, 6]