This is a way of creating an immutable copy of a 2 dimensional array in js if you want to mutate the second array without affecting the original.
Steps (assuming you already have a “board” array created)
// Create original array
let board = [, , , , , ];
// Get copy of original array
let c0 = board.slice();
let c1 = board.slice();
let c2 = board.slice();
let c3 = board.slice();
let c4 = board.slice();
let c5 = board.slice();
let boardCopy = [c0.slice(), c1.slice(), c2.slice(), c3.slice(), c4.slice(), c5.slice()];
// Now you can modify "boardCopy" without affecting "board" at all
1. Store each array inside the ‘board’ array into a variable using the “slice()” function.
2. Create another variable “boardCopy” which is an array that stores all the previous variables we created, also use the “slice()” function.
3. Done! “boardCopy” is now a seperate array from “board” but with the same value and won’t affect the first array when mutated. This can also be done with higher dimensional arrays just by using the same logic.