I want to use javascript spread
operator and I want the result of two different objects to merged using spread operator but it is not working as expected.
For instance, every time, for new request new data is coming and I want to append it a single object. For better consider, consider simple scenario:
const obj1 = {
WellSchema: {
well: [
{wellName: 'check1', uwi: '9000000123'},
{wellName: 'check2', uwi: '8000012432'}
]
}
}
const obj2 = {
WellSchema: {
well: [
{wellName: 'check3', uwi: '2113120002'},
{wellName: 'check4', uwi: '5679001211'},
{wellName: 'check5', uwi: '0987652221'},
{wellName: 'check6', uwi: '5345676542'}
]
}
}
const mutateIt = { ...obj1, ...obj2 }
console.log(mutateIt)
The result I am getting is below:
{
WellSchema: {
well: [
{wellName: 'check3', uwi: '2113120002'},
{wellName: 'check4', uwi: '5679001211'},
{wellName: 'check5', uwi: '0987652221'},
{wellName: 'check6', uwi: '5345676542'}
]
}
}
Anyhow, intended result should be as:
{
WellSchema: {
well: [
{wellName: 'check1', uwi: '9000000123'},
{wellName: 'check2', uwi: '8000012432'}
{wellName: 'check3', uwi: '2113120002'},
{wellName: 'check4', uwi: '5679001211'},
{wellName: 'check5', uwi: '0987652221'},
{wellName: 'check6', uwi: '5345676542'}
]
}
}
Can you suggest, what is wrong in this case? Thanks