How have you been? I want to remove the property "isCorrect" from a nested object.
Original List
id: 1,
questionText: 'This is a test question for tests',
answerOptions: [
{
answerText: 'A',
isCorrect: true
},
{
answerText: 'B',
isCorrect: false
}
],
difficulty: 1
},
{
id: 2,
questionText: 'This is another test question for tests',
answerOptions: [
{
answerText: 'A',
isCorrect: false
},
{
answerText: 'B',
isCorrect: true
}
],
difficulty: 2
}
Expected result
id: 1,
questionText: 'This is a test question for tests',
answerOptions: [
{
answerText: 'A'
},
{
answerText: 'B'
}
],
difficulty: 1
},
{
id: 2,
questionText: 'This is another test question for tests',
answerOptions: [
{
answerText: 'A'
},
{
answerText: 'B'
}
],
difficulty: 2
}
I was able to achieve this using the delete code below but I believe there could be a better approach
const cleanResponses = (questions: Question[]): Question[] => {
questions.forEach(question => {
question.answerOptions.forEach((answer) => {
delete answer.isCorrect
});
})
return questions;
}
I tried the line below but it didn't work as expected :(
const { answerOptions: [{ isCorrect }], ...rest } = question
Thank you