Skip to content

Function: union()

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

Returns the union of multiple arrays while preserving first-seen order. 返回多个数组的并集,并保留首次出现顺序。

Type Parameters

Type ParameterDescription
TThe array item type / 数组元素类型

Parameters

ParameterTypeDescription
...arraysreadonly readonly T[][]The input arrays / 输入数组

Returns

T[]

A deduplicated merged array / 去重后的合并数组

Example

ts
union([1, 2], [2, 3])
// => [1, 2, 3]

Since

1.2.0

Released under the MIT License.