Example 1: Merge Property of Two Objects Using Object.assign()
Output
{
name: "Jack",
age: 26,
gender: "male"
}
In the above example, two objects are merged into one using the Object.assign() method.
The Object.assign() method returns an object by copying the values of all enumerable properties from one or more source objects.
Example 2: Merge Property of Two Objects Using Spread Operator
Output
{
name: "Jack",
age: 26,
gender: "male"
}
In the above example, two objects are merged together using the spread operator ....
Note: In both the above examples, if the two objects have the same key, then the second object's key overwrites the first object's key.