xxAkuma xxAkuma - 1 year ago 77
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download