I have an object that contain a property with an array of objects which I have to change one object.
{id: '3688aa8f-e725-45f4-9513-363a1c019b34',
category: 'Entertainment: Film',
difficulty: 'easy',
question: "What is the orange and white bot's name in "Star Wars: The Force Awakens"?",
answers: [
{id: 'da42762a-e936-42d8-ae61-2a0de53d3c5e', incorrect_answer: 'Austria', isSelected: false},
{id: '44d8549f-31a7-4cdd-8a6b-80cf6a1b853c', incorrect_answer: 'Armenia', isSelected: false},
{id: '2f734291-b4cf-48a0-8e54-3379b7d23ecb', incorrect_answer: 'Australia', isSelected: false},
{id: 'dfa6fa70-3b44-44fe-b80a-fc9da72a6c7f', incorrect_answer: 'Afghanistan', isSelected: false}
]
}
How can I iterate over the answers array and change the property isSelected to true?
I am trying to use the spread operator, but its not working.
findto find the object using the id in the condition, and then update the other value?spreadoperator?yourObj.answers.forEach(e => e.isSelected = true)e.isSelected = true