Monday, June 15, 2026
HomeLanguagesJavascriptLodash _.cloneDeepWith() Method

Lodash _.cloneDeepWith() Method

The Lodash _.cloneDeepWith() method is used to clone value in a recursive way, just the same as the  _.cloneWith() method but performs in a recursive manner.

Syntax:

_.cloneDeepWith( value, customizer )

Parameter: This method accepts two parameters as mentioned above and described below:

  • value: This parameter holds the value which will be cloned in a recursive way.
  • customizer: This parameter holds the function to customize the clone.

Return value: This method returns the cloned value.

Below example illustrate the Lodash _.cloneDeepWith() Method:

Example 1: Cloning Head element.

Javascript




<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        function customizer(value) {
            if (_.isElement(value)) {
                return value.cloneNode(true);
            }
        }
  
        var gfg = _.cloneDeepWith(document.head, customizer);
          
        console.log(gfg === document.head);
        console.log(gfg.nodeName);
        console.log(gfg.childNodes.length);
        console.log(gfg);
    </script>
</body>
 
</html>


Output:

Example 2: Cloning body element.

Javascript




<!DOCTYPE html>
<html>
 
<head>
    <script src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        function customizer(value) {
            if (_.isElement(value)) {
                return value.cloneNode(true);
            }
        }
          
        var gfg = _.cloneDeepWith(document.body, customizer);
          
        console.log(gfg === document.body);
        console.log(gfg.nodeName);
        console.log(gfg.childNodes.length);
        console.log(gfg);
    </script>
</body>
 
</html>


Output:

Reference: https://docs-lodash.com/v4/clone-deep-with/

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS