“Mehrdimensionales Array JS” Code-Antworten

So lesen Sie 2 dimensionales Array in JavaScript


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

JS -Array zweidimensional

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

Mehrdimensionales Array JS

var array = [
  ["0, 0", "1, 0", "2, 0", "3, 0", "4, 0"],
  ["0, 1", "1, 1", "2, 1", "3, 1", "4, 1"],
  ["0, 2", "1, 2", "2, 2", "3, 2", "4, 2"],
  ["0, 3", "1, 3", "2, 3", "3, 3", "4, 3"],
  ["0, 4", "1, 4", "2, 4", "3, 4", "4, 4"],
  ]; // Think of it as coordinates, array[x, y] x = 0; y = 0; is "0, 0" on 
	// this grid

console.log(array[3][3]); // returns "3, 3"
// If you use graphics (ex: p5js or JS Canvas) then this will be a 5x5 map.
// Useful for roguelikes and/or raycasters.
enemi44

JavaScript zweidimensionales Array

var grid = [];
iMax = 3;
jMax = 2;
count = 0;

    for (let i = 0; i < iMax; i++) {
      grid[i] = [];

      for (let j = 0; j < jMax; j++) {
        grid[i][j] = count;
        count++;
      }
    }

// grid = [
//   [ 0, 1 ]
//   [ 2, 3 ]
//   [ 4, 5 ]
// ];

console.log(grid[0][2]); // 4
Light Lemur

Ähnliche Antworten wie “Mehrdimensionales Array JS”

Fragen ähnlich wie “Mehrdimensionales Array JS”

Weitere verwandte Antworten zu “Mehrdimensionales Array JS” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen