A RetroSearch Logo

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

Search Query:

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

Lodash _.defaultsDeep() Method - GeeksforGeeks

Lodash _.defaultsDeep() Method

Last Updated : 15 Jul, 2025

Lodash _.defaultsDeep() method recursively assigns default properties. It is almost the same as the _.defaults() function. This method mutates the object.

Syntax:
_.defaultsDeep(object, [sources]);
Parameters: Return Value:

This method returns the object.

Example 1: In this example, we are using the -.defaultsDeep() method for setting the source's value to the original object.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

// Given object
let info = {
    Name: "GeeksforGeeks",
    password: "gfg@1234",
    username: "your_geeks"
}

// Use of _.defaultsDeep() method
console.log(_.defaultsDeep(info,
    _.defaults(info, { id: 'Id97' })));

Output:

{
Name: 'GeeksforGeeks',
password: 'gfg@1234',
username: 'your_geeks',
id: 'Id97'
}

Example 2: In this example, we are using the -.defaultsDeep() method for setting the source's value to the original object.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

// Use of _.defaultsDeep() method
console.log(_.defaultsDeep(
    {
        'x': { 'y': 20 }
    },
    {
        'x': { 'y': 10, 'z': 30 }
    }
)
);

Output:

{ 'x': { 'y': 20, 'z': 30 } }


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