1// declaration of a two-dimensional array
2// 5 is the number of rows and 4 is the number of columns.
3const matrix = new Array(5).fill(0).map(() => new Array(4).fill(0));
4
5console.log(matrix[0][0]); // 0
6
1let x = [
2 [1, 2, 3],
3 [4, 5, 6],
4 [7, 8, 9]
5];
6console.log(items[0][0]); // 1
7console.log(items[0][1]); // 2
8console.log(items[1][0]); // 4
9console.log(items[1][1]); // 5
10console.log(items);
1var items =[
2
3 [1, 2, 3],//this is row 0
4 [4, 5, 6],//this is row 1
5 [7, 8, 9] //this is row 2
6//cullom 0 cullom 1 cullom2
7
8]
9
10console.log(/* variable name */ items[/*row*/ 0][/*cullom*/ 0]);
1/*having the previous array easy to make is very useful*/
2
3function Array2D(x, y){
4 let arr = Array(x);
5 for(let i = 0; i < y; i++){
6 arr[i] = Array(y);
7 }
8 return arr;
9}
10
11function Array3D(x, y, z){
12 let arr = Array2D(x, y);
13 for(let i = 0; i < y; i++){
14 for(let j = 0; j < z; j++){
15 arr[i][j] = Array(z);
16 }
17 }
18 return arr;
19}
20
21function Array4D(x, y, z, w){
22 let arr = Array3D(x, y, z);
23 for(let i = 0; i < x; i++){
24 for(let j = 0; j < y; j++){
25 for(let n = 0; n < z; n++){
26 arr[i][j][n] = Array(w);
27 }
28 }
29 }
30 return arr;
31}
32/*making the array*/
33let myArray = Array4D(10, 10, 10, 10);
1
2
3
4
5 activities.forEach((activity) => {
6 activity.forEach((data) => {
7 console.log(data);
8 });
9});
1function createArray(row,column) {
2let arr = [];
3
4for(var i=0; i<row; i++){
5 arr[i] = [Math.floor(Math.random() * (10))];
6
7 for(var j=0;j<column;j++){
8 arr[i][j]= [Math.floor(Math.random() * (20))];
9 }
10}
11
12return arr;
13}
14
15var arrVal = createArray(4, 5);
16
17console.log(arrVal);
18