How to merge objects using es6 syntax in js
This article mainly introduces the relevant knowledge of "how to use ES6 syntax to merge objects in js". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use ES6 syntax to merge objects in js" can help you solve the problem.
1. Object.assign () method
Used to copy the values of all enumerable properties from one or more source objects to the target object. It returns the target object.
Use syntax
Object.assign (target,... sources)
Parameters.
Target: target object
Sources: source object
Return value
Target object
Merge objects using the Object.assign () method
/ / a. Copy an object
Var obj = {a: 1 var obj 2}; var copyObj = Object.assign ({}, obj); console.log (copyObj); / / {a: 1je BDR 2}
/ / b. Merge multiple objects to copy code
2. Extension operator
Const summary = {... person,... tools,... attributes}; console.log (summary); that's all for "how to merge objects using es6 syntax in js". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.