Lodash _.assignIn() Method
Last Updated :
03 Nov, 2023
Lodash _.assignIn() method is like the _.assign() method except that it iterates over its own and inherited source properties. Subsequent source objects overwrite property assignments of previous sources. This method mutates the object.
Syntax:
_.assignIn( dest_object, [src_obj]);
Parameters:
- dest_object: This is the destination object.
- src_obj: These are the source objects.
Return Value:
This method returns an object.
Example 1: In this example, we are getting an object which has all of it’s previous inherited object properties because of the lodash _assignIn() method.
Javascript
const _ = require( 'lodash' );
function Gfg1() {
this .a = 1;
}
function Gfg2() {
this .c = 3;
}
Gfg1.prototype.b = 10;
Gfg2.prototype.d = 40;
console.log(_.assignIn({ a: 4 },
new Gfg1, new Gfg2));
|
Output:
{ a: 1, b: 10, c: 3, d: 40 }
Example 2: In this example, we are getting an object which has all of it’s previous inherited object properties because of the lodash _assignIn() method.
Javascript
const _ = require( 'lodash' );
function Gfg1() {
this .a = 1;
}
function Gfg2() {
this .c = 3;
}
console.log(_.assignIn({ a: 4 },
new Gfg1, new Gfg2));
|
Output:
{ a: 1, c: 3 }
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...