How merge two objects in another

I have first object

obj1 = {lastName: "",address1: "Some address"}

and second object

obj2 = {lastName: "Salivan",address1: "1200 Getty Center Dr",}

in the result object

obj3 = {lastName: "Salivan", address1: "Some address"}


The easiest way for me would be to do the following:

const newObject = {

The thing is, it will override your values! So better not merge two similar objects into one, usually it is used to update values of an object or merge different objects into one.

As @AlexSp3 suggested, you can also:

obj3 = Object.assign(obj1, obj2)

For your specific case:

const obj3 = {
   key1: '',
   key2: '',
if (!obj1.key1) {
   obj3.key1 = obj2.key1;
} else {
   obj3.key1 = obj1.key1;

// ... repeat with key2