For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/uniq.md.

uniq es-toolkit

Returns a new array with duplicate elements removed.

const uniqueArray = uniq(arr);

Usage

uniq(arr)

Use uniq when you want to remove duplicate values from an array and keep only unique values. It preserves the order in which they first appear in the original array.

import { uniq } from 'es-toolkit/array';

// Remove duplicates from a number array.
const numbers = [1, 2, 2, 3, 4, 4, 5];
const uniqueNumbers = uniq(numbers);
console.log(uniqueNumbers); // [1, 2, 3, 4, 5]

// Remove duplicates from a string array.
const words = ['apple', 'banana', 'apple', 'cherry', 'banana'];
const uniqueWords = uniq(words);
console.log(uniqueWords); // ['apple', 'banana', 'cherry']

// Remove objects with the same reference from an object array.
const obj1 = { id: 1 };
const obj2 = { id: 2 };
const obj3 = { id: 3 };
const objects = [obj1, obj2, obj1, obj3, obj2];
const uniqueObjects = uniq(objects);
console.log(uniqueObjects); // [{ id: 1 }, { id: 2 }, { id: 3 }]

It returns an empty array for an empty array.

import { uniq } from 'es-toolkit/array';

const emptyArray = uniq([]);
console.log(emptyArray); // []

Parameters

arrreadonly T[]required

The array from which to remove duplicates.

Returns

A new array with duplicates removed. Preserves the order in which they first appear in the original array.

T[]
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.