1const object1 = {
2 name: 'Flavio'
3}
4
5const object2 = {
6 age: 35
7}
8const object3 = {...object1, ...object2 } //{name: "Flavio", age: 35}
9
1var person={"name":"Billy","age":34};
2var clothing={"shoes":"nike","shirt":"long sleeve"};
3
4var personWithClothes= Object.assign(person, clothing);//merge the two object
5
1const a = { b: 1, c: 2 };
2const d = { e: 1, f: 2 };
3
4const ad = { ...a, ...d }; // { b: 1, c: 2, e: 1, f: 2 }
1let obj1 = { foo: 'bar', x: 42 };
2let obj2 = { foo: 'baz', y: 13 };
3
4let clonedObj = { ...obj1 };
5// Object { foo: "bar", x: 42 }
6
7let mergedObj = { ...obj1, ...obj2 };
8// Object { foo: "baz", x: 42, y: 13 }
9
10
1/* For the case in question, you would do: */
2Object.assign(obj1, obj2);
3
4/** There's no limit to the number of objects you can merge.
5 * All objects get merged into the first object.
6 * Only the object in the first argument is mutated and returned.
7 * Later properties overwrite earlier properties with the same name. */
8const allRules = Object.assign({}, obj1, obj2, obj3, etc);