Array.concat() : Concat « Array « JavaScript Tutorial






Syntaxarray.concat(arg1,...argN)


The concat() method adds the elements listed in the parameter list to the end of the existing array and returns the result.

arg1,...argN contains one or more elements to be concatenated to the end of the array.

The original is not changed by this method.

<html>
    <script language="JavaScript">
    <!--
    function displayElements(theArray)
    {
      for(i=0; i<theArray.length; i++)
      {
        document.write(" - ",theArray[i][1]," ");
        document.write(theArray[i][0],"<br>");
      }
    }

    shelf1 = new Array(["A",10],["B",25]);
    document.write("Shelf 1 contains:<br>");
    displayElements(shelf1);
    
    shelf2 = new Array(["C",50],["D",3],["E",8]);
    document.write("Shelf 2 contains:<br>");
    displayElements(shelf2);
    
    inventory = shelf1.concat(shelf2);
    document.write("<br>The total inventory contains:<br>");
    displayElements(inventory);
    --></script>
    </html>








11.9.Concat
11.9.1.Array.concat()
11.9.2.Actual success in copying an array using concat()
11.9.3.Using concat() method to combine two arrays