Object.concat
Object.concat
Function
Merge one or more objects into a new object.
Syntax
object.concat(source1, source2, ...)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| sourceN | Object | No | None | The object to merge; non-object arguments are ignored. |
Return value
| Type | Description |
|---|---|
| Object | Returns the new merged object. |
Return object fields
The returned object first copies the fields of the current object, and then copies the fields of each source object in parameter order; fields with the same name are overwritten by the object passed in later. No fields are written to non-object parameters.
Example
base = {name: 'BT'} result = base.concat({age: 1}) // Output: {"name":"BT","age":1} print result
Notes
- The key with the same name passed in later will overwrite the previous value.
- The original object will not be modified.