A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-assign-method/ below:

Lodash _.assign() Method - GeeksforGeeks

Lodash _.assign() Method

Last Updated : 20 Oct, 2023

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: 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 }


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