Lodash _.clone() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Creates a shallow clone of value. Top-level arrays and objects are new; nested values keep their original references. Part of Lodash 4.x Lang.

Warning: Nested objects and arrays are shared with the source. Need full isolation? Use _.cloneDeep.

Syntax

Call _.clone. Start with this line.

Lodash
_.clone(value)
CallWhat it does
_.clone(value)Primary signature.

Prefer import clone from "lodash/clone" when you want a smaller bundle.

Library declarations
Lodash
_.clone(value)

Parameters

ParameterDescription
valueRequired. Value to shallow-clone

Return Value

Return ValueDescription
*New top-level value (or same primitive)

Lodash Examples

Example 1 — Official: Shallow Array Clone

New array shell; element objects stay shared.

Lodash
var objects = [{ a: 1 }, { b: 2 }];
var shallow = _.clone(objects);

console.log(shallow[0] === objects[0]);
// → true

console.log(shallow === objects);
// → false
Try It Yourself

How It Works

  1. Clone. Lodash builds a new array.
  2. Elements. Each slot still points at the original object.
  3. Identity. shallow[0] === objects[0] is true.
  4. Shell. shallow === objects is false.

Example 2 — Flat Object — Safe Top-Level Edits

Changing a top-level property on the clone leaves the source alone.

Lodash
var source = { x: 1, y: 2 };
var copy = _.clone(source);

copy.x = 9;

// source.x → 1
// copy.x   → 9
// copy !== source → true
Try It Yourself

How It Works

  1. New object. Own enumerable props are copied.
  2. Primitives. x and y are numbers — copied by value.
  3. Edit clone. copy.x = 9 does not touch source.
  4. Best case. Flat data is where shallow clone shines.

Example 3 — Nested Object Still Shared

Mutating a nested property affects both clone and source.

Lodash
var source = { a: 1, b: { c: 2 } };
var copy = _.clone(source);

copy.b.c = 99;

// source.b.c → 99
// copy.b === source.b → true
Try It Yourself

How It Works

  1. Top level. copy is a new object.
  2. Nested. b still points at the same inner object.
  3. Mutation. Changing copy.b.c changes source.b.c.
  4. Fix. Use _.cloneDeep when nested edits must stay private.

Example 4 — Clone a Primitive Array

New array; number elements are safe to reshape independently.

Lodash
var nums = [1, 2, 3];
var copy = _.clone(nums);

copy.push(4);

// nums → [1, 2, 3]
// copy → [1, 2, 3, 4]
// copy !== nums → true
Try It Yourself

How It Works

  1. New array. Length and indexes are independent.
  2. Primitives. Numbers need no deep copy.
  3. push. Extends only the clone.
  4. Same idea as nums.slice() for flat arrays.

Example 5 — clone vs cloneDeep

Deep clone isolates nested objects; shallow does not.

Lodash
var source = { b: { c: 1 } };
var shallow = _.clone(source);
var deep = _.cloneDeep(source);

shallow.b === source.b; // → true
deep.b === source.b;    // → false
Try It Yourself

How It Works

  1. clone. Copies only the outer object.
  2. cloneDeep. Recursively copies nested b.
  3. Compare. Deep clone’s b is a different object.
  4. Pick. Flat edits → clone. Nested edits → cloneDeep.

Browser & Runtime Support

_.clone is a Lodash 4.x Lang helper. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.clone()

Available in [email protected] full builds and the lodash/clone modular import. Closest native shallow patterns: Object.assign({}, obj), { ...obj }, and array.slice(). Lodash also handles more built-in types consistently.

100% With Lodash 4.x
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
_.clone Lodash 4.x+

Bottom line: Safe for production once Lodash is loaded. Prefer import clone from "lodash/clone" for smaller bundles. Remember: shallow — nested references stay shared.

Frequently Asked Questions

_.clone(value) creates a shallow clone of value. Top-level containers (objects, arrays) are new; nested objects and arrays are still shared references.
No. It returns a new top-level value. The input itself is not mutated by clone.
Use cloneDeep when you need nested structures fully isolated before mutating them.
Yes. You get a new array container, but object elements inside remain the same references.
Numbers, strings, booleans, null, and undefined are returned as-is — there is nothing to copy at the top level.
Use import clone from "lodash/clone" or require("lodash/clone") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.clone.

Next: _.cloneDeep()

Recursively clone values so nested objects are fully isolated.

_.cloneDeep() 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.

10 people found this page helpful