0

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: ''}] 
}
]

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.