8 4 2 multi dimensions and array methods

Solutions on MaxInterview for 8 4 2 multi dimensions and array methods by the best coders in the world

showing results for - "8 4 2 multi dimensions and array methods"
Matteo
09 Jul 2016
1/*In a multi-dimensional array, both the inner and outer arrays can
2be altered with array methods. However, bracket notation must be used
3correctly.*/
4
5//To apply a method to the outer array, the syntax is:
6multiArrayName.method();
7
8//To apply a method to one of the inner arrays, the syntax is:
9multiArrayName[indexOfInnerArray].method();
10
11//Example
12Use array methods to add an additional crew array and alter existing arrays.
13
14let shuttleCrews = [
15   ['Robert Gibson', 'Mark Lee', 'Mae Jemison'],
16   ['Kent Rominger', 'Ellen Ochoa', 'Bernard Harris'],
17   ['Eilen Collins', 'Winston Scott',  'Catherin Coleman']
18];
19
20let newCrew = ['Mark Polansky', 'Robert Curbeam', 'Joan Higginbotham'];
21
22// Add a new crew array to the end of shuttleCrews
23shuttleCrews.push(newCrew);
24console.log(shuttleCrews[3][2]);
25
26// Reverse the order of the crew at index 1
27shuttleCrews[1].reverse();
28console.log(shuttleCrews[1]);
29
30//Joan Higginbotham
31//[ 'Bernard Harris', 'Ellen Ochoa', 'Kent Rominger' ]