Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Lodash _.assign() Method

  • Last Updated : 13 Sep, 2020

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.assign() method is used to assign the enumerable string keyed properties of the given source objects to the destination objects. The source objects are applied from left to right and any subsequent sources overwrite the property assignments of the previous sources.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax:

_.assign( 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'); 
  
// Using the ._assign() method
console.log(
  _.assign({ a: 1, c: 3 }, { a: 0 })
);

Output:

{ a: 0, c: 3 }

Example 2: 

Javascript




// Defining Lodash variable 
const _ = require('lodash'); 
  
// Using the ._assign() method
console.log(
  _.assign({ a: 0 }, { a: 1, c: 3 }, { d: 4 })
);

Output:

{ a: 1, c: 3, d: 4 }
My Personal Notes arrow_drop_up
Recommended Articles
Page :