Lodash - toPlainObject method



Syntax

_.toPlainObject(value)

Converts value to a plain object flattening inherited enumerable string keyed properties of value to own properties of the plain object.

Arguments

  • value (*) − The value to convert.

Output

  • (Object) − Returns the converted plain object.

Example

var _ = require('lodash');

function Foo() {
   this.b = 2;
}
Foo.prototype.c = 3;
 
console.log(_.assign({ 'a': 1 }, new Foo));
console.log(_.assign({ 'a': 1 }, _.toPlainObject(new Foo)));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

{ a: 1, b: 2 }
{ a: 1, b: 2, c: 3 }
lodash_lang.htm
Advertisements