Skip to content

union ​

The union function returns a new array containing all unique elements from two or more arrays.

Syntax ​

typescript
union<T>(...arrays: T[][]): T[];

Parameters ​

NameTypeDescription
arraysT[][]Two or more source arrays

Returns ​

TypeDescription
T[]New array with unique elements

Examples ​

typescript
union([1, 2], [2, 3], [3, 4]); // => [1, 2, 3, 4]

Notes ​

  • The order of elements is preserved according to the first occurrence.
  • Does not modify the original arrays.

References ​

Released under the MIT License.