clone
Creates a shallow copy of a value — one level deep, unlike cloneDeep.
Unlike a plain { ...value } spread, this correctly reconstructs Date,
Map, Set, and arrays instead of producing an empty (or wrong-shaped)
plain object for them. Primitives are returned as-is. Any other object
(including class instances not listed above) has its own enumerable string
keys shallow-copied into a plain object — the same fallback cloneDeep
uses, so the two stay consistent for types neither one special-cases.
Available since v3.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | T | The value to shallow-clone |
Returns
Section titled “Returns”T — A shallow copy of value
Examples
Section titled “Examples”Shallow-copy a plain object
Section titled “Shallow-copy a plain object”Top-level keys are copied; nested values still share references (shallow).
Correctly clones Date/Map/Set, unlike a spread
Section titled “Correctly clones Date/Map/Set, unlike a spread”{ …new Date() } produces {} — clone() doesn’t have that problem.
