Instructor
Yogesh Chawla Replied on 10/01/2022
Mutating the array means changing the original array. Now without changing the original array, we can do this:
items.forEach( item => item.done = true );
console.log(items);
or
var arr_copy = JSON.parse(JSON.stringify(items));
arr_copy.forEach( item => item.done = true );
console.log(arr_copy);
console.log(items);
forEach does not mutate the original array.
or use map
let items2 = items.map(a => {return {...a}})
items2.find(a => a.id == 2).task = "modified";
items2.forEach( item => item.done = true );
console.log(items2);
console.log(items);