The new Array.with method gives you an immutable syntax for changing values of an array at a specified index.
Sometimes .map
will be more efficient. So, in this lesson we'll compare both methods while replacing an object at a specific index.
var todos = [
{ id: 1, completed: false, task: "Write a blog post" },
{ id: 2, completed: true, task: "Review pull requests" }
]
var idx = todos.findIndex(item => item.id === 1)
// toggle the completed of todo with the known idx
todos.with(idx, {...todos.at(idx), completed: !todos.at(idx).completed})
标签:idx,completed,ES2024,id,new,array,method,todos From: https://www.cnblogs.com/Answer1215/p/18206160