Lodash教程

Lodash toPlainObject method

语法

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

参数

value (*) − The value to convert.

输出

(Object) − Returns the converted plain object.

实例

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

输出

{ a: 1, b: 2 }
{ a: 1, b: 2, c: 3 }
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4