• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

3. Arrays and Objects > 3.6. Combining Arrays

Combining Arrays

NN 4, IE 4

Problem

You want to blend two or more separate arrays into one larger array.

Solution

To join arrays together, use the concat( ) method of the array object, passing a reference to the other array as a parameter:

var comboArray = myArray.concat(anotherArray);

Arrays joined through the concat( ) method are not altered. Instead, the concat( ) method returns the combined array as a new value, which you can preserve in a separate variable. The base array (the one used to invoke the concat( ) method) comes first in the combined array.

For combining multiple arrays, pass the additional arrays as comma-delimited parameters to the concat( ) method:

var comboArray = myArray.concat(otherArray1, otherArray2, otherArray3);

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint