Skip to content

unique

The unique function returns a new array containing only the unique elements from the original array.

Syntax

typescript
unique<T>(array: T[]): T[];

Parameters

NameTypeDescription
arrayT[]Source array

Returns

TypeDescription
T[]New array with unique elements

Examples

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

Notes

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

References

Released under the MIT License.