This is the array and I want to replace the elements "A" and "B" with "D". I don't want to mutate the original array , So I have used spread operator. But still my original array getting mutating whenever I will update the newArr. I want originalArray should be [["A", 2],["B",1]]
and newArr should be [["D", 2],["D",1]]
Can anyone suggest me the solution for this
let originalArray = [["A", 2],["B",1]];
let newArr = [ ...originalArray ];
for(let i=0;i<newArr.length;i++){
newArr[i][0] = "D";
}
console.log(originalArray )
console.log(newArr)