Así que tengo estas pocas líneas de código:
console.log(...cells); let testCells = [...cells]; testCells[index].shape = selectedShape; testCells[index].player = player; console.log(...cells); Lo interesante es que es console.log() devolviendo lo siguiente.
No lo entiendo muy bien, ¿por qué cambian cells ? No hay otra parte del código que pueda interferir con cells . ¿Algun consejo?
Parece que aunque está distribuyendo todos los objetos en la nueva matriz, sigue siendo una referencia a los objetos antiguos. Puede romper la referencia usando JSON.stringify y JSON.parse para evitar relaciones antiguas no deseadas.
const cells = [ {shape: 0, player: 0}, {shape: 0, player: 0}, {shape: 0, player: 0}, {shape: 0, player: 0}, {shape: 0, player: 0}, {shape: 0, player: 0}, {shape: 0, player: 0}, {shape: 0, player: 0}, {shape: 0, player: 0}, ]; console.log(...cells); const breakRef = obj => JSON.parse(JSON.stringify(obj)); let testCells = breakRef(cells); testCells[0].shape = 1; testCells[0].player = 0; console.log(...cells);