The _.extendOwn() function is used to copy only own properties over to the destination object. This function is similar to the _.extend() function.
Syntax:
_.extendOwn(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 of own properties over to 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(_.extendOwn(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(_.extendOwn({ Â Â Â Â Â Â Â Â Â Â Â Â Company: 'neveropen', Â Â Â Â Â Â Â Â Â Â Â Â Address: 'Noida' Â Â Â Â Â Â Â Â }, { Â Â Â Â Â Â Â Â Â Â Â Â Contact: '+91 9876543210', Â Â Â Â Â Â Â Â Â Â Â Â Email: 'abc@gfg.com' Â Â Â Â Â Â Â Â }, { Â Â Â Â Â Â Â Â Â Â Â Â Author: 'Ashok' Â Â Â Â Â Â Â Â })); Â Â Â Â </ script > </ body > Â Â </ html > |
Output: