Skip to content

Function: uniqueArray() ​

uniqueArray<T>(arr): T[]

Remove the duplicate items of an array, keeping the first occurrence of each, in order. The items are compared as by Set (SameValueZero): NaN equals NaN, 1 and '1' differ, and two objects are equal only when they are the same object. The array is not modified.

Type Parameters ​

T ​

T

Parameters ​

arr ​

T[]

The array; an empty array gives an empty array.

Returns ​

T[]

A new array without duplicates.

Example ​

typescript
import {uniqueArray} from 'lakutata/utils'

console.log(uniqueArray([3, 1, 3, 2, 1]))
//[3, 1, 2]

Released under the MIT License.