0

Given I have the following object:

let obj = { 
    cat: "paws",
    dogs: {
        lab: "Christopher",
        otherLab: "Lady Buba"
    }
}

let objTwo = {
    dogs: {
        lab: "some new name"
    }
}

How can I merge the above two objects so that the final result is:

{
    cat: "paws",
    dogs: {
        lab: "some new name",
        otherLab: "Lady Buba"
    }
}

I've attempted to use spread operators with let finalObj = {...obj, ...objTwo}, but this entirely replaces the value of dogs, so that the end result is:

{
    cat: "paws",
    dogs: {
        lab: "some new name",
    }  
}

which isn't what I want.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Dimitrije
  • 11
  • 1

0 Answers0