Encountering a Puzzling Dilemma:
I recently created a copy of an array and was surprised to find that when I made changes to the copied array, the original array also changed. Why did this happen?
const groups = [[1, 2, 3, 4 ,5], [2,3]];
const sets = [...groups];
sets[1].push(9000); // Added a number only to 'sets', not 'groups'
console.log(sets);
console.log(groups);
This phenomenon appears to occur specifically with arrays within arrays!
What could be causing this issue and how can it be resolved?