Thursday, October 9, 2025
HomeLanguagesJavascriptLodash _.assign() Method

Lodash _.assign() Method

Lodash _.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.

Syntax:

_.assign( 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 assigning a value to an object by using the _.assign() method.

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:  In this example, we are assigning two object values to an object by using the _.assign() method.

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 }
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS