jQuery.extend()Method
Examples
Iterate over array elements and modify the first object
Try it »
Definition and Usage
The jQuery.extend() function is used to merge the contents of one or more objects into the target object.
Note:1. If only one parameter is specified for $.extend(), it means the target parameter is omitted. At this point, target is the jQuery object itself. In this way, we can add new functions to the global object jQuery.
2. If multiple objects have the same property, the latter will override the former's property value.
Syntax
Indicates whether to deep merge
Warning:Passing false as the first parameter is not supported.
| Parameters | Description |
|---|---|
| deep | Optional. Boolean type. Indicates whether to deeply merge objects. Defaults to false. If this value is true, and a property with the same name in multiple objects is also an object, then the properties of that "property object" will also be merged. |
| target | Object type. The target object, to which member properties of other objects will be attached. |
| object1 | Optional. Object type. The first object to be merged. |
| objectN | Optional. Object type. The Nth object to be merged. |
More Examples
Merge two objects recursively
Recursively merge two objects and modify the first object.
Merge the defaults and options objects
Merge the defaults and options objects without modifying the defaults object. This is a common plugin development pattern.
Other Extensions
jQuery Miscellaneous Methods