Skip to main content

Get union of arrays

JavaScript version

const union = (...arr) => [...new Set(arr.flat())];

TypeScript version

const union = <T,_>(...arr: T[][]): T[] => [...new Set(arr.flat())];

Example

union([1, 2], [2, 3], [3]); // [1, 2, 3]

Comments