“2D Array JavaScript” Kode Jawaban

JS array dua dimensi

// 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
Evergreen Tomato

cara membaca array 2 dimensi dalam javascript


        
            
        
     activities.forEach((activity) => {
    activity.forEach((data) => {
        console.log(data);
    });
});
Friendly Fowl

Membuat array 2D di JS

var x = new Array(10);

for (var i = 0; i < x.length; i++) {
  x[i] = new Array(3);
}

console.log(x);
Obedient Ox

JavaScript mengisi 2 dimensi array

const fillSquareMatrix = (size) => {
  return Array(size)
    .fill()
    .map((u,y) => Array(size)
         .fill()
         .map((u,x) => y * size + x + 1));
};

console.log(fillSquareMatrix(3));
Friendly Finch

Membuat array 2D di JavaScript

var [r, c] = [5, 5]; 
var m = Array(r).fill().map(()=>Array(c).fill(0));
Breakable Boar

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]);
Alive Aardvark

Jawaban yang mirip dengan “2D Array JavaScript”

Pertanyaan yang mirip dengan “2D Array JavaScript”

Lebih banyak jawaban terkait untuk “2D Array JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya