Good afternoon, how in JavaScript to put an array in a multidimensional array, without wrapping in quotes?

Those. there is an array — you need to thrust 3 more arrays into it with 3 elements in each.

Ultimately, I need to get a multi-dimensional array of this type:

var big_array= [[2, 5, 7], [3, 1, 4], [6, 8, 9]]; 

I tried to add arrays via push and supposedly emulate arrays ...

 big_array.push("["+var1+","+var2+","+var3+"]"); //это пример добавления первого массива с данными (2,5,7) Но результат получается вот такой, с кавычками: ["[2,5,7]"] //это big_array 

When should be:

 [[2,5,7]] 

How can I do that?

  • big_array.push(var1, var2, var3); - alexlz
  • @alexlz - you add 3 elements, TSu need to add an array with three elements - Zowie

2 answers 2

 big_array.push("["+var1+","+var2+","+var3+"]"); // LOL big_array.push([var1, var2 ,var3]);// не?.. 

Are you stuffing a string and wondering if a string is added to the array? O_O

  • And why am I getting a little bit different? > big_array [[[2, 5, 7], [3, 1, 4], [6, 8, 9]]] - alexlz
  • and .. string .. for sure) thanks) - Denis Masster
  • So you are doing something wrong, here without options. Besides, I have no idea what exactly you want to get. PS: I would venture to suggest that you stupidly call push not for that array. If you haven’t figure it out yet - provide the code - Zowie
  • No, I just assigned one-dimensional arrays to var'am. As can be seen from the result. - alexlz

EXAMPLE OF CREATING A MASSIF USING THE DESIGNER Array OBJECT:

 var arr = new Array(3);//Создание массива на 3 элемента arr[0] = new Array(3); //вставл. в первый элемент массив на 3 элемента arr[1] = new Array(3); //вставл. в второй элемент массив на 3 элемента arr[2] = new Array(3); //вставл. в третий элемент массив на 3 элемента //... 

EXAMPLE OF CREATING A MASS BY USING SQUARE BOXES:

 var arr = []; //Создание пустого массива arr[0] = []; //вставл. в первый элемент массив arr[1] = []; //вставл. в второй элемент массив arr[2] = []; //вставл. в третий элемент массив //... 

NOTE: In JavaScript, Array objects are dynamic, i.e. the number of elements can be added or abbreviated at any time of the program execution time. Based on this, you can add the required number of elements of the desired type to any level of the multidimensional array, both in the first and second methods.

EXAMPLE OF CREATING A MULTI-DIMENSIONAL MASSIF (10x10) USING A CYCLE:

  var tаblе = new Array (10); // 10 строк таблицы for (var i=0; i < tаblе.length; i++) { tаblе[i] = new Array(10); // 10 столбцов } 
  • very timely, thanks) - Denis Masster