Concatenation of two arrays with javascript

If you want to concatenate two arrays with javascript then you can use the concat method of an array to do so. Below script will join up the two arrays and returns a new array consists of the combination elements from the two.

var apple = ["apple", "pie"];
var pen = ["pen", "pencil!"];
var applepen = apple.concat(pen);

alert(applepen);

If you put the above code in any html5 web page and load that page then you will see the below alert box pops up.

Applepen
Applepen