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.

user229044
  • 232,980
  • 40
  • 330
  • 338

1 Answers1

2

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

Try:

var c = a.concat(b);
gen_Eric
  • 223,194
  • 41
  • 299
  • 337