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 :: yt playlist downloader js 
Javascript :: array.findindex is not a function 
Javascript :: Is there an “exists” function for jQuery 
Javascript :: tinymce editor description value is not getting onclick js 
Javascript :: how to check if expo app is running on the web 
Javascript :: HH:mm with am pm jquery 
Javascript :: react counter animation 
Javascript :: e editable select no button 
Javascript :: Make a program that filters a list of strings and returns a list with only your friends name in it.javascript 
Javascript :: reverse array in javascript 
Javascript :: redirect with data jquery 
Javascript :: get difference of minutes between two time based on am, pm 
Javascript :: postfix date javascript 
Javascript :: nextjs override page route 
Javascript :: beanstalk nodejs default port 
Javascript :: vuejs input call the value 
Javascript :: delete cookie 
Javascript :: jquery selector input name regex 
Javascript :: json returning object object 
Javascript :: js display 
Javascript :: how to mouse hover svg 
Javascript :: choco node 17 
Javascript :: how a message persist in the localstorage in javascript 
Javascript :: difference 
Javascript :: js wrap function 
Javascript :: empty array js 
Javascript :: input as html in console 
Javascript :: How to make PWAs installable js 
Javascript :: how to create an object in javascript 
Javascript :: adding data attributes to react-select 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =