Answers for "2d array in javascript"

12

js array two dimensional

// declaration of a two-dimensional array
// 5 is the number of rows and 4 is the number of columns.
const matrix = new Array(5).fill(0).map(() => new Array(4).fill(0));

console.log(matrix[0][0]); // 0
Posted by: Guest on May-24-2020
5

how to make a 2d array in js

let x = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
];
console.log(items[0][0]); // 1
console.log(items[0][1]); // 2
console.log(items[1][0]); // 4
console.log(items[1][1]); // 5
console.log(items);
Posted by: Guest on June-05-2021
1

2d array javascript

var items =[
     
  [1,        2,       3],//this is row 0
  [4,        5,       6],//this is row 1
  [7,        8,       9] //this is row 2
//cullom 0   cullom 1   cullom2
  
]

console.log(/* variable name */ items[/*row*/ 0][/*cullom*/ 0]);
Posted by: Guest on August-29-2021
1

how to make a 4 dimensional array in JavaScript

/*having the previous array easy to make is very useful*/

function Array2D(x, y){
 let arr = Array(x);
  for(let i = 0; i < y; i++){
   arr[i] = Array(y);
  }
  return arr;
}

function Array3D(x, y, z){
 let arr = Array2D(x, y);
      for(let i = 0; i < y; i++){
       for(let j = 0; j < z; j++){
        arr[i][j] = Array(z);
       }
      }
  return arr;
}

function Array4D(x, y, z, w){
 let arr = Array3D(x, y, z);
      for(let i = 0; i < x; i++){
       for(let j = 0; j < y; j++){
        for(let n = 0; n < z; n++){
        arr[i][j][n] = Array(w);
       }
       }
      }
  return arr;
}
/*making the array*/
let myArray = Array4D(10, 10, 10, 10);
Posted by: Guest on September-23-2020
4

how to read 2 dimensional array in javascript

activities.forEach((activity) => {
    activity.forEach((data) => {
        console.log(data);
    });
});
Posted by: Guest on May-09-2020
0

2d array in javascript

function createArray(row,column) {
let arr = [];

for(var i=0; i<row; i++){
    arr[i] = [Math.floor(Math.random() * (10))];

    for(var j=0;j<column;j++){
        arr[i][j]= [Math.floor(Math.random() * (20))];
    }
}

return arr;
}

var arrVal = createArray(4, 5);

console.log(arrVal);
Posted by: Guest on September-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language