2

I have several arrays of arrays... e.g.

var a = [[45, "question1", "answer1"], [22, "question2", "answer2"]];
var b = [[55, "question3", "answer3"], [12, "question4", "answer4"]];

Each array is coming in from a different page

I then wanted to push them together to get

var c = [[45, "question1", "answer1"], [22, "question2", "answer2"], [55, "question3", "answer3"], [12, "question4", "answer4"]];

I did this by

var c = a;

c.push(b);

When I tried to sort this, it comes out all wrong which tells me that the push has done something like

var c = [[45, "question1", "answer1"], [22, "question2", "answer2"]], [[55, "question3", "answer3"], [12, "question4", "answer4"]];

Can someone help, or point me towards the answer? I need to be able to sort on the first element of the array across all of the joined array.

0

1 Answer 1

2

You're looking for .concat(), not .push().

Try:

var c = a.concat(b);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, thats cracked it! I think I have been sitting in front of this screen for too long....

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.