Saturday, December 28, 2024
Google search engine
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:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments