https://www.sitepoint.com/merging-objects-javascript/
You can use either the spread operator (...) or the Object.assign() method. Both methods create a new object by combining the properties of the source objects.
Using the Spread Operator (...):
The spread operator, introduced in ES6, allows you to expand the properties of objects into another object.
const num1 = { a: 10, b: 20 };
const num2 = { b: 30, c: 40 };
const obj = { ...num1, ...num2 };
console.log(obj); // Output: { a: 10, b: 30, c: 40 }
In this example, the property b from num2 overwrites the property b from num1.
Using Object.assign() Method:
The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It also performs a shallow copy, and properties from later source objects overwrite those from earlier ones if they have the same key.
const obj1 = { a: 1, b: 2 };
const obj2 = { b: 3, c: 4 };
const merged = Object.assign({}, obj1, obj2);
console.log(merged); // Output: { a: 1, b: 3, c: 4 }
Here, an empty object {} is used as the target, ensuring that obj1 and obj2 remain unaltered.