Reputation: 21
Would appreciate any help on how to update the value property of any of the answer objects.
{
name: 'John',
surname: 'Doe',
answer: [{value: '' }, {value: ''}]
},
{
name: 'Alice',
surname: 'Malice',
answer: [{value: '' }, {value: ''}]
}
]
Upvotes: 0
Views: 69
Reputation: 996
You'll just need to index into those arrays and set the values as needed. Here's a function that does just that:
const people = [...<my list of objects>...];
const updateValue = (name, answerIndex, newValue) => {
const person = people.find((i) => i.name === name);
person.answer[answerIndex].value = newValue;
}
Upvotes: 1