Skip to content

unique

Removes duplicate values from an array. null and undefined are treated as empty arrays and return [].

Available since v1.9.0

import { unique } from '@helpers4/array';
// or, from the all-in-one package (same code, one install):
import { unique } from 'helpers4/array';
unique<T>(array: readonly T[] | null | undefined): T[]
ParameterTypeDescription
arrayreadonly T[] | null | undefinedThe array to remove duplicates from

T[] — New array with unique values only

Returns a new array with duplicate values removed.

unique([1, 2, 2, 3, 3, 3])
// => [1, 2, 3]

View source on GitHub