xxAkuma xxAkuma - 5 months ago 19
Javascript Question

How to concatenate 2 one-dimensional arrays into 1 two-dimensional array in JavaScript?

I would like to do the following:

var arrayA = new Array;
var arrayB = new Array;
var arrayC = new Array;

arrayA = [["one", "two", "three"]];
arrayB = [["four", "five", "six"]];

so that I could get

arrayC = [["one", "two", "three"], ["four", "five", "six"]];

How would I accomplish it?


You can just create a new array that has the other arrays as elements.

var arrayC = [arrayA[0], arrayB[0]];

BTW, there's no point in initializing the variables to new Array if you're just going to assign a different array to them.