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)
Call
What 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
Parameter
Description
value
Required. Any. The object, array, Date, or primitive to copy. If it has a clone method, that method is called instead.
Return Value
Return Value
Description
deep copy
A 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 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.
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.
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.
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 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.