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

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 :: javascript odd or even 
Javascript :: jquery loop through model list 
Javascript :: if statement js 
Javascript :: copy array 
Javascript :: javascript get max value in array of objects 
Javascript :: number of factors 
Javascript :: promise object 
Javascript :: jquery textarea value 
Javascript :: onhover 
Javascript :: js new function 
Javascript :: .reverse javascript string 
Javascript :: ~~ in js 
Javascript :: traversing in jquery 
Javascript :: sort include sequelize 
Javascript :: electron Uncaught ReferenceError: require is not defined 
Javascript :: knexjs char 
Javascript :: strip whitespace from shopify liquid output 
Javascript :: react native app exit 
Javascript :: how to send the value of the javascript variable value to my php page 
Javascript :: javascript Symbol Properties 
Javascript :: javascript setTimeout() method returns the interval id 
Javascript :: JavaScript Object Prototypes 
Javascript :: salesforce set hours javascript 
Javascript :: bootstrap on tabs change 
Javascript :: Warning: Problem validating app.json: Unable to perform cache refresh for 
Javascript :: phaser rotate container facing point 
Javascript :: javascript multiplication without operator 
Javascript :: when end sound show alert 
Javascript :: navbar permanently in react router dom v6 
Javascript :: javascript show alert if browser is not google chrome 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =