Codehs 8.1.5 Manipulating 2d Arrays Official
In CodeHS, you can declare and initialize a 2D array using the following syntax:
var arrayName = [[value1, value2, ...], [value3, value4, ...], ...]; For example: Codehs 8.1.5 Manipulating 2d Arrays
arrayName.splice(rowIndex, 1); For example: In CodeHS, you can declare and initialize a
var myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; myArray.splice(1, 1); // myArray = [[1, 2, 3], [7, 8, 9]]; Adding a new column to a 2D array requires modifying each row individually. You can use a loop to iterate over each row and add the new value. You can use a loop to iterate over
var myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; for (var i = 0; i < myArray.length; i++) { myArray[i].push(i + 1); } // myArray = [[1, 2, 3, 1], [4, 5, 6, 2], [7, 8, 9, 3]]; Removing a column from a 2D array can be done using a similar approach. You can use a loop to iterate over each row and remove the column value.