Object.assign() Merge objects
Last updated: 2026-09-09
Object.assign() Merge objects
Object.assign copies enumerable properties from source objects to the target — a shallow merge.
| Category | Objects |
|---|---|
| ES version | ES5 |
📝 Syntax
const merged = Object.assign(target, source1, source2);
⚙️ Parameters
| target | The target object — properties are copied here and returned. |
|---|---|
| sourceN | One or more source objects. |
Returns:The merged target object.
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
{ theme: 'dark', lang: 'zh', size: 'md' }
💡 Tip Pass {} as target to avoid mutation; spread { ...a, ...b } is even better.
⚠️ Warning Shallow merge — nested objects share references.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| Object.assign() | ✓ v1 | ✓ v12 | ✓ v1.5 | ✓ v3 | ✓ v10.5 |
| Supported by all modern browsers | |||||
🏷️ Related Objects
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
QIs Object.assign a deep copy?
ANo — shallow. Use structuredClone for deep copies.
QObject.assign vs spread?
ASame result; spread is cleaner and non-mutating.
QHow to merge nested objects?
AShallow only — use a deep-merge library for nested objects.