JavaScript Object.assign() Method
The Object.assign() static method copies the properties of one or more source objects onto a target object and returns the target.
Description
The Object.assign() static method copies all own enumerable properties from the source objects to the target object, later sources overwriting earlier ones. It changes and returns the target, so Object.assign({}, a, b) creates a merged copy.
The copy is shallow: nested objects are shared, not duplicated. In modern code, object spread syntax, { ...a, ...b }, does the same thing for new objects. For a deep copy, use structuredClone().
Only own, enumerable properties are copied, including symbol-keyed ones; getters are run and their values copied, rather than the getter itself. Properties are assigned in order, so if a setter on the target throws, the copy stops part-way. null and undefined sources are skipped without error.
Syntax
Object.assign(target, source1, source2, ...)Parameters
- targetThe object to copy properties into. It is changed and returned.
- source1, source2, ...Objects whose own enumerable properties are copied, in order.
Return Value
The target object.
Example
Browser Support
The following information will show you the current browser support for the Object.assign() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





