Friday, January 16, 2026
HomeLanguagesJavascriptLodash _.assignIn() Method

Lodash _.assignIn() Method

The 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: This method accepts two parameters as mentioned above and described below:

  • dest_object: This is the destination object.
  • src_obj: These are the source objects.

Return Value: This method returns an object.

Example 1:

Javascript




// Defining Lodash variable 
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:

Javascript




// Defining Lodash variable 
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 }
RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6845 POSTS0 COMMENTS
Nicole Veronica
11976 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12061 POSTS0 COMMENTS
Shaida Kate Naidoo
6984 POSTS0 COMMENTS
Ted Musemwa
7217 POSTS0 COMMENTS
Thapelo Manthata
6932 POSTS0 COMMENTS
Umr Jansen
6910 POSTS0 COMMENTS