Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

creating a 2d array in js

var x = new Array(10);

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

console.log(x);
Comment

creating 2d array in javascript

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

2d array in js

a = Array(5).fill(0).map(x => Array(10).fill(0))
Comment

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]);
Comment

how to create two dimensional array in js

const m = 4;
const  n = 5;
let arr = new Array(m); // create an empty array of length n
for (var i = 0; i < m; i++) {
  arr[i] = new Array(n); // make each element an array
}
console.log(arr); //  Output: [ [ <5 empty items> ], [ <5 empty items> ], [ <5 empty items> ], [ <5 empty items> ] ]
Comment

2d array in js

var x = new Array(10);

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

console.log(x);
 Run code snippetHide results
Comment

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);
Comment

javascript creating and accessing 2d array

// creating 1d array
var array = new Array(10);

// add an array to each 1d element, hence creating 2d array
for (var i = 0; i < array.length; i++) {
    array[i] = new Array(2);
}

// accessing: first element of the first ro
console.log(array[0][0]);
Comment

2d array js

 2d array
Comment

2d array JS

<script>
  
// Create one dimensional array
    var gfg = new Array(2);
  
document.write("Creating 2D array <br>");
  
// Loop to create 2D array using 1D array
for (var i = 0; i < gfg.length; i++) {
    gfg[i] = new Array(2);
}
  
var h = 0;
  
// Loop to initialize 2D array elements.
for (var i = 0; i < 2; i++) {
    for (var j = 0; j < 2; j++) {
        gfg[i][j] = h++;
    }
}
  
// Loop to display the elements of 2D array. 
for (var i = 0; i < 2; i++) {
    for (var j = 0; j < 2; j++)    {
        document.write(gfg[i][j] + " ");
    }
    document.write("<br>");
} 
</script>
Comment

2d array JS

<script>
  
// Create one dimensional array
var gfg = new Array(3);
  
// Loop to create 2D array using 1D array
document.write("Creating 2D array <br>");
for (var i = 0; i < gfg.length; i++) {
    gfg[i] = [];
}
var h = 0;
var s = "GeeksforGeeks";
  
// Loop to initialize 2D array elements.
for (var i = 0; i < 3; i++) {
    for (var j = 0; j < 3; j++) {
  
        gfg[i][j] = s[h++];
    }
}
  
// Loop to display the elements of 2D array.
for (var i = 0; i < 3; i++) {
    for (var j = 0; j < 3; j++)
  
    {
        document.write(gfg[i][j] + " ");
    }
    document.write("<br>");
}
  
</script>
Comment

2d arrays js

let items = [
  [1, 2],
  [3, 4],
  [5, 6]
];
console.log(items[0][0]); // 1
console.log(items[0][1]); // 2
console.log(items[1][0]); // 3
console.log(items[1][1]); // 4
console.log(items);
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use a regex expression in kibana query 
Javascript :: yup string date schema validation 
Javascript :: find an object from array of objects javascript 
Javascript :: javascript download html to pdf 
Javascript :: radio button checked jquery 
Javascript :: React Native typescript start new project 
Javascript :: how to detect click outside div 
Javascript :: Missing script: "start" react 
Javascript :: nodejs return value 
Javascript :: how to replace all occurrences of a string in javascript 
Javascript :: recieve voice channel audio discord.js 
Javascript :: convert namednodemap to object 
Javascript :: split and join in node js 
Javascript :: three.js cube 
Javascript :: unix timestamp js 
Javascript :: post request with authorization 
Javascript :: ndjson to json javascript 
Javascript :: remove eslint check react native 
Javascript :: innerhtml 
Javascript :: javascript get character from string 
Javascript :: setstate array 
Javascript :: how to increment variable value in javascript 
Javascript :: foreach method javascript 
Javascript :: date now javascript 
Javascript :: define an async function 
Javascript :: graphql query 
Javascript :: svg path clickable 
Javascript :: getting the value of pi in javascript 
Javascript :: check if an array contains a number in javascript 
Javascript :: Math.avg 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =