I have a question object
let question = {
id: 1,
description: 'how is the service',
answers: [
{
id: 1,
description: 'poor'
},
{
id: 2,
description: 'good'
}
]
};
let newquestion = {
description: 'new question',
answers: [
'new poor',
'new good'
]
}
I need to map the answer values to the corresponding description property in the answers array inside the question object.
I need the output to look like,
q = {
id: 1,
description: 'new question',
answers: [
{
id: 1,
description: 'new poor'
},
{
id: 2,
description: 'new good'
}
]
};
i tried,
const q = {...question, ...newquestion};
But I get output like,
q = {
id: 1,
description: 'new question',
answers: [
'new poor',
'new good'
]
};
I'm new to typescript and javascript. Please assist on where I'm going wrong.