JavaScript tutorial:
concat method (Array)

Applies to: Array Object, String Object

The concat method combines the two arrays together.

Syntax

array1.concat(array2)

The concat method syntax has these parts:

Part

Description

array1

Required. An Array object to concatenate with array2.

array2

Required. An Array object to concatenate to the end of array1.

Return value

Returns an new array consisting of a combination of two arrays.

Example

The concat method returns an Array object containing the concatenation of array1 and array2.

If an object reference is copied from either array1 or array2 to the result, the object reference in the result still points to the same object. Changes to that object are reflected in both arrays.

The following example illustrates the use of the concat method:

function ConcatArray()
{
    var a = new Array(0,1,2,3,4);
    var b = new Array(5,6,7,8,9);
    var c = a.concat(b);
    return(c);
}

document.write(ConcatArray());

To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: concat Method (String), join Method