I have an array of object like
const test = [{id: 1, text: "Test"}, { id: 2 , text: "Test 2" } ]
const index = test.findIndex((listItem) => listItem === test[0])
Here I am trying to update the value of text key
using the index.
I have a solution like this:
const editItemText = (value) => {
const newList = replaceItemAtIndex(todoList, index, {
...item,
text: value,
});
setTodoList(newList);
};
const replaceItemAtIndex = [...arr.slice(0, index), newValue, ...arr.slice(index + 1)];
is there any other option to do so ? Also How does the given solution works ?
Thanks.