8.4.2. Multi-Dimensions and Array Methods
/*In a multi-dimensional array, both the inner and outer arrays can
be altered with array methods. However, bracket notation must be used
correctly.*/
//To apply a method to the outer array, the syntax is:
multiArrayName.method();
//To apply a method to one of the inner arrays, the syntax is:
multiArrayName[indexOfInnerArray].method();
//Example
Use array methods to add an additional crew array and alter existing arrays.
let shuttleCrews = [
['Robert Gibson', 'Mark Lee', 'Mae Jemison'],
['Kent Rominger', 'Ellen Ochoa', 'Bernard Harris'],
['Eilen Collins', 'Winston Scott', 'Catherin Coleman']
];
let newCrew = ['Mark Polansky', 'Robert Curbeam', 'Joan Higginbotham'];
// Add a new crew array to the end of shuttleCrews
shuttleCrews.push(newCrew);
console.log(shuttleCrews[3][2]);
// Reverse the order of the crew at index 1
shuttleCrews[1].reverse();
console.log(shuttleCrews[1]);
//Joan Higginbotham
//[ 'Bernard Harris', 'Ellen Ochoa', 'Kent Rominger' ]