Ramda.js R.clone() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.clone() answers a simple question: give me a copy I can edit without touching the original. You pass one value. You get a deep copy. Nested arrays and objects are new. Numbers, strings, and booleans come back as themselves. Dates and regular expressions are copied. Functions stay the same function object.

The official sample is the whole idea. Clone [{}, {}, {}] and both === checks fail: the array is new, and each nested object is new. Native JavaScript’s cousins are structuredClone(value) (deep, throws on functions) and { ...obj } (shallow). Lodash _.cloneDeep is the named deep copy; _.clone is only one level. Ramda has one helper: R.clone is always deep for the types it supports. Need one new key, not a full copy? That is R.assoc or R.assocPath.

Syntax

Call R.clone. Start with this line.

Ramda
R.clone(value)
CallWhat it does
R.clone(value)Primary signature.
R.clone(...)Call the object helper.

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

Library declarations
Ramda
R.clone(value)

Parameters

ParameterDescription
valueRequired. Any. The object, array, Date, or primitive to copy. If it has a clone method, that method is called instead.

Return Value

Return ValueDescription
deep copyA new tree for objects and arrays. Dates, regexes, and typed arrays are copied. Primitives are returned as-is. Functions are the same reference. Map and Set are not copied in Ramda 0.30 — you get the original.

Ramda Examples

📚 Getting Started

The official Ramda sample, then the same nested record compared with a shallow assoc copy.

Example 1 — Official Nested List

The clone is a new array. Each nested object is a new object. Both identity checks fail.

Ramda
const objects = [{}, {}, {}];
const objectsClone = R.clone(objects);

objects === objectsClone;
//=> false

objects[0] === objectsClone[0];
//=> false
Try It Yourself

How It Works

Ramda allocates a new array, then clones each {} into a new object. A shallow copy such as objects.slice() would fail the first check and pass the second. That is the docs sample from ramdajs.com.

Example 2 — Deep vs assoc Shallow

Changing a nested name on the clone leaves the original Ada. assoc only copied the top level, so user is still shared.

Ramda
const orig = { user: { name: 'Ada' } };
const deep = R.clone(orig);
const shallow = R.assoc('role', 'dev', orig);

deep.user.name = 'Lin';

orig;
//=> { user: { name: 'Ada' } }

deep;
//=> { user: { name: 'Lin' } }

shallow.user === orig.user;
//=> true
Try It Yourself

How It Works

clone copied user as well as the outer object, so writing Lin cannot reach orig. assoc added role on a new outer object but reused the same user pointer. That is why nested edits belong on a clone, or on R.assocPath if you only need one nested key.

📈 Practical Patterns

Dates, functions, primitives, then shared inner references and a custom clone() method.

Example 3 — Date Copy

Dates are copied by value. Changing the clone’s year leaves the original timestamp unchanged.

Ramda
const orig = new Date('2026-08-19T00:00:00.000Z');
const copy = R.clone(orig);

copy.setUTCFullYear(2020);

orig.toISOString();
//=> '2026-08-19T00:00:00.000Z'

copy.toISOString();
//=> '2020-08-19T00:00:00.000Z'

orig === copy;
//=> false
Try It Yourself

How It Works

The implementation builds new Date(value.valueOf()). The two dates hold the same instant until you mutate one. A shallow copy of an object that contains a Date would still share that Date. Regular expressions are copied the same way.

Example 4 — Functions and Primitives

Numbers and null come back as themselves. A method on a cloned object is the same function, not a copied function body.

Ramda
function greet() { return 'hi'; }

const orig = { n: 7, greet: greet };
const copy = R.clone(orig);

R.clone(7);
//=> 7

R.clone(null);
//=> null

copy.n;
//=> 7

copy.greet === orig.greet;
//=> true
Try It Yourself

How It Works

Primitives have no inner references, so returning them is a copy. Functions are not data trees — the docs assign them by reference. Native structuredClone would throw on that greet property. clone keeps the method so the copy still runs.

Example 5 — Shared Refs and clone()

Two keys that shared one object still share one (new) object after clone. A value with its own clone() method is dispatched to that method instead.

Ramda
const node = { id: 1 };
const tree = { a: node, b: node };
const copy = R.clone(tree);

tree.a === tree.b;
//=> true

copy.a === copy.b;
//=> true

copy.a === tree.a;
//=> false

const custom = {
  x: 1,
  clone: function () { return { copied: true, x: this.x }; }
};

R.clone(custom);
//=> { copied: true, x: 1 }
Try It Yourself

How It Works

Ramda remembers nodes it has already copied. a and b both pointed at node, so the clone has one new node behind both keys. That is the docs note about shared references. If the value implements clone, that method wins — useful for your own types.

Browser Support

R.clone() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.clone()

Load Ramda 0.1.0 or later via CDN or npm, then call R.clone with one value. No extra browser API is required.

100% With Ramda 0.1.0+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.clone() Universal

Bottom line: Safe in any project that includes Ramda 0.1.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected]. Native structuredClone needs a modern engine and is a separate API.

Frequently Asked Questions

R.clone(value) returns a deep copy of value. Nested arrays and objects are new. Dates and regular expressions are copied. Functions are kept by reference. Added in v0.1.0. The original value is not mutated.
Given const objects = [{}, {}, {}], R.clone(objects) is a new array. objects === objectsClone is false, and objects[0] === objectsClone[0] is also false because each nested object is cloned.
No. It returns a new tree. Changing a nested field on the clone does not change the source. That is the opposite of a shallow copy such as R.assoc, which shares nested objects by reference.
No. The docs say functions are assigned by reference rather than copied. The clone's method is the same function object as the original.
assoc copies one top-level key and shares nested objects. clone copies the whole tree. structuredClone is the native deep copy; it supports Map and Set, but throws on functions. clone keeps functions by reference and does not copy Map or Set in Ramda 0.30.
No. R.clone is a stable Ramda object helper from v0.1.0. It is not deprecated, experimental, or non-standard.

Continue to R.dissoc()

Learn how to drop one key on a cloned object using Ramda R.dissoc().

R.dissoc() 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