Wednesday, July 8, 2026
HomeLanguagesJavascriptLodash _.defaultsDeep() Method

Lodash _.defaultsDeep() Method

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:

  • object: This parameter holds the destination object.
  • sources: This parameter holds the source objects.

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: "neveropen",
    password: "gfg@1234",
    username: "your_neveropen"
}
 
// Use of _.defaultsDeep() method
console.log(_.defaultsDeep(info,
    _.defaults(info, { id: 'Id97' })));


Output:

{
Name: 'neveropen',
password: 'gfg@1234',
username: 'your_neveropen',
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 } }
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

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12016 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6977 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS