Wednesday, July 3, 2024
HomeLanguagesJavascriptUnderscore.js _.extend() Function

Underscore.js _.extend() Function

The _.extend() function is used to create a copy of all of the properties of the source objects over the destination object and return the destination object. The nested arrays or objects will be copied by using reference, not duplicated.

Syntax:

_.extend(destination, *sources)

Parameters: This function accept two parameters as mentioned above and described below:

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

Return Value: It returns a copy all of the properties of the source objects over the destination object, and return the destination object.

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        var obj1 = {
            key1: 'Geeks',
        };
  
        var obj2 = {
            key2: 'neveropen',
        };
  
        console.log(_.extend(obj1, obj2));
    </script>
</body>
  
</html>


Output:

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        var obj1 = {
            key1: 'Geeks',
        };
  
        var obj2 = {
            key2: 'neveropen',
        };
  
        console.log(_.extend({
            Company: 'neveropen',
            Address: 'Noida'
        }, {
            Contact: '+91 9876543210',
            Email: 'abc@gfg.com'
        }, {
            Author: 'Ashok'
        }));
    </script>
</body>
  
</html>


Output:

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments