This is the original data
const data = {
"field1": {
"name": 'Anuv',
"marks": {
"eng": 43,
"hindi": 23
},
"age": 21
},
"field2": {
"school": 'DAV'
}
}
I am trying to update the name
const updatedValue = {
"field1": {
"name": "Anuv Gupta"
}
}
This is the expected data. It should have all the field and the updated name value as well.
const expectedData = {
"field1": {
"name": 'Anuv Gupta',
"marks": {
"eng": 43,
"hindi": 23
},
"age": 21
},
"field2": {
"school": 'DAV'
}
}
I have tried using these
expectedData = Object.assign({}, data, updatedValue)
as well as
expectedData = { ...data, ...updatedValue },
both of them returns this object
const obj = {
"field1": {
"name": 'Anuv Gupta',
},
"field2": {
"school": 'DAV'
}
}
How do I fix this and get the expectedData object?