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?

Brian Powell
  • 3,336
  • 4
  • 34
  • 60

1 Answers1

10

Use the concat function:

var complete = array1.concat(array2);
eladcon
  • 5,815
  • 1
  • 16
  • 19
  • sweet - I knew there was a function like this, I just couldn't remember what it was called. Thank you! Worked like a charm :) – Brian Powell Mar 27 '15 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()`. – Jason Sperske Mar 27 '15 at 20:17