Skip to content

Function: uniq()

ts
function uniq<T>(array): T[];

Removes duplicate values from an array while preserving order. 在保留顺序的前提下移除数组中的重复值。

Type Parameters

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

Parameters

ParameterTypeDescription
arrayreadonly T[]The source array / 源数组

Returns

T[]

A new array with unique values / 去重后的新数组

Example

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

Since

1.2.0

Released under the MIT License.