June 2014
Intermediate to advanced
696 pages
38h 52m
English
You can combine arrays using the concat() method but not the + method. In the following code, the variable arr3 contains a string representation of the elements in arr1 and arr2. Whereas 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.
Read now
Unlock full access