Seguridad de la página de inicio

Codehs 8.1.5 | Manipulating 2d Arrays

var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; for (var i = 0; i < array.length; i++) { array[i].splice(1, 1); // remove column at index 1 } console.log(array); // output: [[1, 3], [4, 6], [7, 9]] Suppose you want to create a 3x3 grid of buttons, where each button has a unique value. You can use a 2D array to represent the grid and manipulate it to add or remove buttons.

var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; array[1][1] = 10; // update element at row 1, column 1 console.log(array); // output: [[1, 2, 3], [4, 10, 6], [7, 8, 9]] To add a new row to a 2D array, you can use the push() method. Codehs 8.1.5 Manipulating 2d Arrays

var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; array.push([10, 11, 12]); // add new row console.log(array); // output: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] To add a new column to a 2D array, you need to iterate through each row and add a new element. var array = [[1, 2, 3], [4, 5,