1

I have two arrays:

ArrayOne = new Array(Array1, Array2);
ArrayTwo = new Array(Array3, Array4);
ArrayThree = new Array();

I want to do:

ArrayThree = ArrayOne.concat(ArrayTwo);

With the result:

ArrayThree = {ArrayOne, ArrayTwo}

However this operation results in:

ArrayThree = {ArrayOne[0], ArrayOne[1]... ArrayOne[n], ArrayTwo[0], ArrayTwo[1]... ArrayTwo[n]};

Any advice on how to get {ArrayOne, ArrayTwo} so the original array object is maintained?

Thanks

1
  • Backticks (`) are for inline code. To format a block of lines as code, indent them an extra four spaces. The "{}" button in the editor toolbar does this for you. Edit your question and try it out. Click the orange question mark in the editor toolbar for more information and tips on formatting. Commented Nov 29, 2011 at 8:22

2 Answers 2

1
var ArrayThree = [ ArrayOne, ArrayTwo ];
Sign up to request clarification or add additional context in comments.

Comments

1

If you can't use concat function...

var ArrayThree = [ArrayOne, ArrayTwo];

or even,

var ArrayThree = new Array(ArrayOne, ArrayTwo);

not a problem if you have ArrayThree previously initialized

3 Comments

I think it is because new Array is discouraged. But it is not strictly wrong, is it? And the preferred version is also mentioned.
I didn't know that it's discouraged. Yeah probably because of that
Downvoted because I believe this answer originally suggested use of the concat method, which is exactly what the OP didn't want. If I am mistaken, my apologies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.