-5

I know in PHP I can use the array_merge function to do this, but let's say I have two arrays like this:

var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];

How do I merge these two arrays into another array arr3 so that it looks like this:

var arr3 = [1, 2, 3, 4, 5, 6];

Thank you

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
user765368
  • 19,590
  • 27
  • 96
  • 167
  • [MDN Array concat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) – dc5 Aug 29 '13 at 19:14
  • 3
    If you [google your question title](https://www.google.com/search?q=Merge+two+arrays+in+javascript), the first result is a stackoverflow question with the answer. – Jason P Aug 29 '13 at 19:15

1 Answers1

2

Try this

var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];

var array3 = arr1.concat(arr2 ); 
Kevin Boucher
  • 16,426
  • 3
  • 48
  • 55
Farhan
  • 752
  • 4
  • 10