Combining Arrays

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.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.77.76