object.assign()
时间: 2023-09-04 08:15:57 浏览: 42
Object.assign() is a built-in JavaScript method that is used to copy the values of all enumerable properties from one or more source objects to a target object. It returns the target object after the properties from the source object(s) have been copied over.
The syntax for using Object.assign() is as follows:
```
Object.assign(target, ...sources)
```
- `target`: The target object that will receive the properties from the source object(s).
- `sources`: One or more source objects that contain the properties to be copied to the target object.
The properties from the source object(s) will overwrite any existing properties in the target object with the same name. If multiple source objects contain properties with the same name, the last source object in the argument list will overwrite the previous ones.
Object.assign() can be used for a variety of tasks such as creating a copy of an object, merging multiple objects into one, or updating an existing object with new properties.