Home javascript Two-dimensional arrays (matrix)

Two-dimensional arrays (matrix)




Is there an opportunity to declare in JavaScript two-dimensional arrays except option:

mass = [[1,2,3], [4,5,6], [7,8, nine]]

i.e. If the dimension of the array is transmitted to the function, and the function generates an array with the specified dimension?

Answer 1, Authority 100%

Of course.

Function Matrixarray (Rows, Columns) {
 var arr = new array ();
 For (var i = 0; i & lt; rows; i ++) {
  arr [i] = new array ();
  For (var j = 0; j & lt; columns; j ++) {
   Arr [i] [j] = i + j + 1; // instead of i + j + 1 we write any filler. In the simplest case - NULL
var MyMatrix = Matrixarray (3.3);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions