There is nothing wrong with your code and it is down to the point, however, if you're looking for a more concise and modern way you can use the 'Object.keys' method along with 'Array.prototype.reduce' to create your merged object.
The Object.keys() static method[
^]
The reduce() method[
^]
const obj1 = {
1: "John",
2: "Tom",
3: "Harry"
};
const obj2 = {
1: "Doe",
2: "Jones",
3: "Newman"
};
const obj3 = Object.keys(obj1).reduce((result, key) => {
result[key] = `${obj1[key]} ${obj2[key]}`;
return result;
}, {});
console.log(obj3);
I have created a fiddle for you which gives the desired output -
Merged object[
^]