Export (0) Print
Expand All
Expand Minimize

concat Method (Array) (Windows Scripting - JScript)

Updated: March 2009

Returns a new array consisting of a combination of two or more arrays.

                      array1.concat([item1[, item2[, . . . [, itemN]]]])

array1

Required. The Array object to which all other arrays are concatenated.

item1,. . ., itemN

Optional. Additional items to add to the end of array1.

The concat method returns an Array object containing the concatenation of array1 and any other supplied items.

The items to be added (item1 itemN) to the array are added, in order, from left to right. If one of the items is an array, its contents are added to the end of array1. If the item is anything other than an array, it is added to the end of the array as a single array element.

Elements of source arrays are copied to the resulting array as follows:

  • For an object reference copied from any of the arrays being concatenated to the new array, the object reference continues to point to the same object. A change in either the new array or the original array will result in a change to the other.

  • For a numeric or string value being concatenated to the new array, only the value is copied. Changes in a value in one array does not affect the value in the other.

The following example illustrates the use of the concat method when used with an array:

function ConcatArrayDemo(){
   var a, b, c, d;
   a = new Array(1,2,3);
   b = "JScript";
   c = new Array(42, "VBScript");
   d = a.concat(b, c);
   //Returns the array [1, 2, 3, "JScript", 42, "VBScript"]
   return(d);
}

Date

History

Reason

March 2009

Fixed syntax bug in sample code.

Content bug fix.

Community Additions

ADD
Show:
© 2014 Microsoft