2

I have two arrays that are built in exactly the same way that I need to add together. One can be added to the end of the other, or a new array can be created containing the data of the two, it doesn't matter to me.

Here's a screenshot showing what this looks like NOW in Chrome's console:

enter image description here

What I've Tried

I tried simply adding the two together...

var complete = [];
complete.push(array1);
complete.push(array2);  

but this still leaves me with the upper [Object, Object] and [Object, Object, Object] levels that I'm trying to get rid of.

How do I merge the individual Objects from these arrays into one?

0

1 Answer 1

10

Use the concat function:

var complete = array1.concat(array2);
2
  • sweet - I knew there was a function like this, I just couldn't remember what it was called. Thank you! Worked like a charm :) Commented Mar 27, 2015 at 20:17
  • In case you wanted to fill out your clear and correct answer, .push() takes an element and pushes it onto the end of an array. That element might also be an array, but it is different than concat(). Commented Mar 27, 2015 at 20:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.