You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Arrays can hold different data types, even other arrays! A multi-dimensional array is one with entries that are themselves arrays.
2
2
3
3
//1) Define and initialize the arrays specified in the exercise to hold the name, chemical symbol and mass for different elements.
4
-
4
+
letelement1=['hydrogen','H',1.008]
5
+
letelement2=['helium','He',4.003]
6
+
letelement26=['iron','Fe',55.85]
5
7
//2) Define the array 'table', and use 'push' to add each of the element arrays to it. Print 'table' to see its structure.
6
-
8
+
lettable=[]
9
+
table.push(element1);
10
+
table.push(element2);
11
+
table.push(element26);
12
+
console.log(table);
7
13
//3) Use bracket notation to examine the difference between printing 'table' with one index vs. two indices (table[][]).
8
-
14
+
console.log(table[1]);
15
+
console.log(table[0,1]);
9
16
//4) Using bracket notation and the table array, print the mass of element1, the name for element 2 and the symbol for element26.
10
17
11
18
//5) 'table' is an example of a 2-dimensional array. The first “level” contains the element arrays, and the second level holds the name/symbol/mass values. Experiment! Create a 3-dimensional array and print out one entry from each level in the array.
0 commit comments