Answers for "creating 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
0

creating 2d array in javascript

var [r, c] = [5, 5]; 
var m = Array(r).fill().map(()=>Array(c).fill(0));
Posted by: Guest on October-16-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language