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);
Sign up to request clarification or add additional context in comments.

2 Comments

sweet - I knew there was a function like this, I just couldn't remember what it was called. Thank you! Worked like a charm :)
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().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.