const obj1 = {a: 1, b: 2};
const obj2 = {c: 2, d:4, e:5};
Object.assign(obj2, obj1);
const result = Object.keys(obj2);
console.log(result)
Output:
[ 'c', 'd', 'e', 'a', 'b' ]
- Object.assign(obj2, obj1) : merges
obj1properties intoobj2.( adding the properties fromobj1intoobj2directly.) - Object.keys(obj2): Gets the keys of the modified obj2.
- Since
obj1’s keys (aandb) are added toobj2,resultincludes all keys from both objects.