You can combine arrays into a single array using the concat()
method but not the +
method. In the following code, the variable arr3
contains a string representation of the elements in arr1
added to a string representation of the elements in arr2
. The variable arr4
, in the following code, is an array with the combined elements from arr1
and arr2
:
var arr1 = [1,2,3];
var arr2 = ["three", "four", "five"]
var arr3 = arr1 + arr2;
var arr4 = arr1.concat(arr2);
Note
You can combine an array of numbers and an array of strings. Each item in the array will keep its own object type. However, as you use the items in the array, you need to keep track of arrays that have more than one data type so that you do not run into problems.