-1

There are two objects, we have to put first object into the second object.

first Object

var inputData1 = {
    'first':{'name':'aa', 'age':11},
    'second': {'name':'aa', 'age':11}
};

Second Object

var inputData2 = {
    'group': {
         _id: null
    }
}

Output Object

var output = {
    'group':{
       _id: null,
       first: {name:'aa', 'age':11},
       second: {name: 'bb', age: 21} 
    }
 }
1

1 Answer 1

2

You can use Object.assign function. It copies the enumerable properties of the objects into the destination object.

var inputData1 = {
    'first':{'name':'aa', 'age':11},
    'second': {'name':'aa', 'age':11}
};

var inputData2 = {
    'group': {
        _id: null
    }
};

Object.assign(inputData2.group, inputData1);

console.log(inputData2);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.