Ramda.js R.uniq() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.uniq(list) returns a new list with only one copy of each value. The first copy stays in its original position; every later copy is dropped (official Ramda docs).

Stable since v0.1.0: R.uniq is not deprecated, experimental, or non-standard. Note: it compares with R.equals (by value), not === — so [42] and [42] are duplicates, but 1 and '1' are not.

Syntax

Call R.uniq. Start with this line.

Ramda
R.uniq(list) — one argument Official [1, 1, 2, 1] → [1, 2]; [1, '1'] → [1, '1']; [[42], [42]] → [[42]]
CallWhat it does
R.uniq(list) — one argument Official [1, 1, 2, 1] → [1, 2]; [1, '1'] → [1, '1']; [[42], [42]] → [[42]]Primary signature.
R.uniq(...)Call the list helper.

Prefer import { uniq } from "ramda" when you want a named import.

Library declarations
Ramda
R.uniq(list) — one argument Official [1, 1, 2, 1] → [1, 2]; [1, '1'] → [1, '1']; [[42], [42]] → [[42]]

Parameters

ParameterDescription
listRequired. The array to clean up; values can be of any type

Return Value

Return ValueDescription
*A new array of first copies, in their original order

Ramda Examples

Example 1 — Official: Remove Repeated Numbers

Keep the first copy of each value. A number and a string are never the same value.

Ramda
console.log(R.uniq([1, 1, 2, 1]));  // [1, 2]
console.log(R.uniq([1, '1']));      // [1, '1']
Try It Yourself

How It Works

  1. First 1. Not seen yet, so it is kept.
  2. Second and fourth 1. Already seen, so both are dropped.
  3. 2. New, so it is kept after the 1: [1, 2].
  4. 1 vs '1'. R.equals(1, '1') is false because the types differ, so both stay.

Example 2 — Official: Deep Equality vs Set

Two separate arrays with the same contents count as one value for R.uniq, but not for a Set.

Ramda
console.log(R.uniq([[42], [42]]));      // [[42]]
console.log([...new Set([[42], [42]])]);  // [[42], [42]]
Try It Yourself

How It Works

  1. Two arrays. Each [42] is a separate array object in memory.
  2. R.uniq. R.equals compares the contents, finds them equal, and keeps only the first.
  3. Set. A Set compares objects by reference; two different arrays are two different entries.
  4. Rule of thumb. For lists of arrays or objects, R.uniq matches what you usually mean by “duplicate”.

Example 3 — Collect Unique Tags from Posts

Flatten every post’s tags into one list, then remove the repeats.

Ramda
const posts = [
  { title: 'Intro', tags: ['js', 'ramda'] },
  { title: 'Lists', tags: ['ramda', 'arrays'] },
  { title: 'Style', tags: ['css', 'js'] }
];

const allTags = R.pipe(R.chain(R.prop('tags')), R.uniq);

console.log(allTags(posts));  // ['js', 'ramda', 'arrays', 'css']
Try It Yourself

How It Works

  1. Flatten. R.chain(R.prop('tags')) gives ['js', 'ramda', 'ramda', 'arrays', 'css', 'js'].
  2. Remove repeats. R.uniq drops the second 'ramda' and the second 'js'.
  3. Order. Tags appear in the order they were first used.
  4. Reusable. R.pipe wraps both steps into one function, allTags.

Example 4 — Remove Duplicate Objects

Objects with the same keys and values are duplicates, whatever order the keys are written in.

Ramda
const cart = [
  { id: 1, qty: 2 },
  { id: 2, qty: 1 },
  { qty: 2, id: 1 }
];

console.log(R.uniq(cart));
// [{ id: 1, qty: 2 }, { id: 2, qty: 1 }]

const changed = [{ id: 1, qty: 2 }, { id: 1, qty: 5 }];
console.log(R.uniq(changed).length);                    // 2
console.log(R.uniqBy(R.prop('id'), changed).length);    // 1
Try It Yourself

How It Works

  1. Deep compare. { qty: 2, id: 1 } has the same keys and values as the first item, so it is dropped.
  2. Every field counts. qty: 2 and qty: 5 differ, so R.uniq keeps both objects.
  3. Compare one field. R.uniqBy with R.prop('id') treats same-id objects as duplicates and keeps the first.
  4. Pick the right tool. Exact duplicates: R.uniq. Same record: R.uniqBy.

Example 5 — R.uniq vs R.dropRepeats

Remove every repeat, or only repeats that sit next to each other.

Ramda
const moves = ['up', 'up', 'down', 'up', 'down'];

console.log(R.uniq(moves));         // ['up', 'down']
console.log(R.dropRepeats(moves));  // ['up', 'down', 'up', 'down']
Try It Yourself

How It Works

  1. R.uniq. Remembers every value it has kept, so any later 'up' or 'down' is dropped.
  2. R.dropRepeats. Only compares each item with the one right before it, so it removes just the second 'up'.
  3. Different questions. R.uniq answers “which values appear?”; R.dropRepeats answers “what changed, in order?”.
  4. Choose by meaning. For a history of moves, R.dropRepeats keeps the sequence; for a list of options, R.uniq is right.

Browser & Runtime Support

R.uniq() is plain ES5 JavaScript inside Ramda 0.1.0+. Ramda uses a native Set to speed up numbers and strings when one exists, and falls back to its own lookup table when it does not — the results are identical either way.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.uniq()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun. The examples on this page use const, arrow functions and spread syntax (ES2015), supported by every modern browser.

100% With Ramda loaded
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.uniq() Universal

Bottom line: Safe in any project with Ramda (check with npm ls ramda). Its behavior has been stable for many versions. These labs load [email protected].

Frequently Asked Questions

R.uniq(list) returns a new array with only one copy of each value. It keeps the first copy of every value, in the original order, and drops later duplicates. The official sample R.uniq([1, 1, 2, 1]) returns [1, 2].
It uses R.equals, which compares by value. Arrays and objects with the same contents are duplicates, so R.uniq([[42], [42]]) returns [[42]]. Values of different types are not equal, so R.uniq([1, '1']) keeps both.
A Set compares objects by reference, so two separate [42] arrays both stay. R.uniq compares by value and keeps only one. They also differ on zero: a Set merges 0 and -0, while R.uniq keeps both. For plain numbers and strings the results are otherwise the same.
R.dropRepeats only removes a value when it repeats the item right before it, so R.dropRepeats([1, 1, 2, 1]) returns [1, 2, 1]. R.uniq remembers every value it has kept, so the same list becomes [1, 2].
Use R.uniqBy(R.prop('id'), list). R.uniq only removes objects that are equal in every field, so { id: 1, qty: 2 } and { id: 1, qty: 5 } both stay. R.uniqBy compares just the id and is also much faster on large lists.
No. R.uniq has been a stable Ramda list function since v0.1.0. It is not deprecated, experimental, or non-standard.

Next: R.uniqBy()

Remove duplicates by a computed key, such as an id or a lowercase name.

R.uniqBy() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful