Skip to content

@pmun/utils / union

Function: union()

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

返回所有数组的并集(去重后的所有元素)

Type Parameters

T

T

Parameters

arrays

...T[][]

要合并的数组

Returns

T[]

并集数组

Example

ts
union([1, 2], [2, 3], [3, 4]) // [1, 2, 3, 4]
union([1, 1, 2], [2, 3, 3]) // [1, 2, 3]
union(['a', 'b'], ['b', 'c']) // ['a', 'b', 'c']