0

There are 2 multi-dimensional objects with different depths.

you need to combine them into one object

tried to use the Object.assign function, but without success If the title is different then you need to write them. And if the same leave 1 sample objects:

{
  "title":"Cars",
  "children":[
  {
    "title":"Stars",
         "children":[
        { 
          "title":"Fuel","children":[
            {
            "title":"132"
            }
          ]
        }
        ]
    }
  ],
  "title":"Cars",
  "children":[
  {
    "title":"Stars",
         "children":[
        { 
          "title":"Power","children":[
            {
            "title":"Yes"
            }
          ]
        }
        ]
    }
  ]

}

expected result:



{
  "title":"Cars",
  "children":[
  {
    "title":"Stars",
         "children":[
        { 
          "title":"Fuel",
            "children":[
             {
               "title":"132"
             }
          ],

          "title":"Power",
            "children":[
             {
               "title":"Yes"
             }
          ]
        }
        ]
    }
  ]

}

  • Possible duplicate of [How to deep merge instead of shallow merge?](https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge) – Ari Seyhun Jul 26 '19 at 03:55
  • The object structure is wrong, there's two `tittle` properties on the top level object, you presumably want to wrap up the object before the second `title` property, open up a new object for the second `title` property and beyond and wrap it all in an array. – MinusFour Jul 26 '19 at 03:56
  • You'll need to use a custom function - I recommend lodash https://lodash.com/docs/#merge – Ari Seyhun Jul 26 '19 at 03:56

0 Answers0