Last Updated : 03 Nov, 2023
Lodash _.toPlainObject() method is used to convert the specified value to a plain object flattening inherited enumerable string keyed properties of value to own properties of the plain object.
Syntax:_.toPlainObject(value);Parameters:
This method returns the converted plain object.
Example 1: In this example, we are converting the given object into the plain object by the use of the lodash _.toPlainObject() method.
JavaScript
// Defining Lodash variable
const _ = require('lodash');
// Initializing a function gfg()
function gfg() {
this.a = 1;
}
// Calling _.toPlainObject() function
console.log(_.assign({ 'b': 2 },
_.toPlainObject(new gfg)));
Output:
{ b: 2, a: 1 }
Example 2: In this example, we are converting the given object into the plain object by the use of the lodash _.toPlainObject() method.
JavaScript
// Defining Lodash variable
const _ = require('lodash');
// Initializing a function gfg()
function gfg() {
this.c = 4;
}
gfg.prototype.b = 2;
// Calling _.toPlainObject() function
console.log(_.toPlainObject(new gfg));
Output:
{ c: 4, b: 2 }
Note: This will not work in normal JavaScript as it requires the lodash library to be installed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4