Lodash _.toPlainObject() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Converts value to a plain object, flattening inherited enumerable string-keyed properties onto own properties of the result. Part of Lodash 4.x Lang.

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.toPlainObject. Start with this line.

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

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

Library declarations
Lodash
_.toPlainObject(value)

Parameters

ParameterDescription
valueRequired. Any value to convert

Return Value

Return ValueDescription
*New plain object

Lodash Examples

Example 1 — Official: assign Needs the Flatten

Show why wrapping new Foo matters for _.assign.

Lodash
function Foo() {
  this.b = 2;
}
Foo.prototype.c = 3;

_.assign({ a: 1 }, new Foo);
// → { a: 1, b: 2 }

_.assign({ a: 1 }, _.toPlainObject(new Foo));
// → { a: 1, b: 2, c: 3 }
Try It Yourself

How It Works

  1. Instance. Own key b; prototype has enumerable c.
  2. Raw assign. Copies only own keys → c skipped.
  3. Flatten. toPlainObject makes c an own key.
  4. Wrapped assign. Now c is merged too.

Example 2 — Flatten Alone

See the plain object without merging into another target.

Lodash
function Foo() {
  this.b = 2;
}
Foo.prototype.c = 3;

_.toPlainObject(new Foo);
// → { b: 2, c: 3 }

_.isPlainObject(_.toPlainObject(new Foo));
// → true
Try It Yourself

How It Works

  1. Walk. Collects enumerable string keys from the instance and prototypes.
  2. Copy. Writes them onto a fresh {}.
  3. Plain. Result has a normal Object prototype.
  4. Check. _.isPlainObject confirms the shape.

Example 3 — String Index Keys

Primitives with enumerable indexes become keyed objects.

Lodash
_.toPlainObject("hi");
// → { "0": "h", "1": "i" }

_.toPlainObject([10, 20]);
// → { "0": 10, "1": 20 }
Try It Yourself

How It Works

  1. Indexes. Characters / elements are enumerable string keys.
  2. length. Non-enumerable, so it is not copied.
  3. Result. A plain map of those indexes.
  4. Note. Prefer _.toArray when you want an array.

Example 4 — Object Spread Misses Inherited Keys

Compare modern spread with toPlainObject.

Lodash
function Foo() {
  this.b = 2;
}
Foo.prototype.c = 3;

var inst = new Foo();

({ ...inst });
// → { b: 2 }              // own only

_.toPlainObject(inst);
// → { b: 2, c: 3 }        // own + inherited
Try It Yourself

How It Works

  1. Spread. Copies own enumerable keys only.
  2. Inherited. Prototype c is invisible to spread.
  3. toPlainObject. Walks like keysIn and includes c.
  4. Choose. Use Lodash when prototypes matter.

Example 5 — null and undefined

Non-object inputs without enumerable keys yield an empty object.

Lodash
_.toPlainObject(null);
// → {}

_.toPlainObject(undefined);
// → {}

_.toPlainObject(42);
// → {}
Try It Yourself

How It Works

  1. Safe. No throw on null / undefined.
  2. Empty. Nothing enumerable to copy → {}.
  3. Numbers. Same idea — no string keys to flatten.
  4. Guard. Still returns a plain object you can merge safely.

Browser & Runtime Support

_.toPlainObject 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. There is no single native equivalent; people approximate with Object.create / for…in or Object.assign plus keysIn-style walks.

✓ Stable · Lodash 4.x

_.toPlainObject()

Available in [email protected] full builds and the lodash/toPlainObject modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

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
_.toPlainObject Lodash 4.x+

Bottom line: Safe for production once Lodash is loaded. Prefer import toPlainObject from "lodash/toPlainObject" for smaller builds. Use when APIs need inherited enumerable keys as own properties.

Frequently Asked Questions

It converts value into a new plain object and copies inherited enumerable string-keyed properties onto that object as own properties.
The result is always a plain Object (Object.prototype). Inherited enumerable keys from the input are copied as own keys — it does not drop them.
Spread ({ ...obj }) copies only own enumerable keys. _.toPlainObject also walks the prototype chain (like keysIn).
_.assign copies only own enumerable keys. Wrapping with toPlainObject first lets assign merge inherited enumerable keys too — the official docs demo.
No. Nested objects and arrays stay the same references. Use _.cloneDeep when you need a deep clone.
They produce {}. Strings and arrays contribute their enumerable index keys; non-enumerable length is not copied.

Next: _.toSafeInteger()

Convert a value to a safe integer within ±(2⁵³ − 1).

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

9 people found this page helpful