Skip to content

unique

Remove duplicate values from an array.

Usage

js
import { unique } from 'js-cool'

Signature

typescript
function unique<T>(arr: T[]): T[]

Parameters

ParameterTypeDescription
arrT[]The array to deduplicate

Returns

T[] - A new array with duplicate values removed.

Examples

js
unique([1, 2, 2, 3, 3, 4]) // [1, 2, 3, 4]
unique(['a', 'b', 'a', 'c']) // ['a', 'b', 'c']
unique([1, '1', 1]) // [1, '1']

Notes

  • Uses strict equality (===) for comparison
  • Preserves the order of first occurrence
  • Returns a new array, does not modify the original

Released under the MIT License.