+ 2

guys how can i make 2D arrays in javascript ?!??! can you explane it to me with an example please!!

2D Arrays

14th Jun 2017, 7:09 AM
Vahan Soulian
Vahan Soulian - avatar
2 Respostas
+ 15
let's make a 10x10 multiplication board var board = [] // main array for(var i=1; i<=10; i++){ var row=[] // a single row for(var j=1; j<=10; j++){ row.push(i*j) // push value } board.push(row) // push single row array } and for printing it for(var i=0; i<10; i++){ document.write("<br>") for(var j=0; j<10; j++){ document.write("["+board[i][j]+"]"); } document.write("<br>") }
14th Jun 2017, 7:22 AM
Burey
Burey - avatar
+ 1
thanks that helped
14th Jun 2017, 9:34 AM
Vahan Soulian
Vahan Soulian - avatar