A-C > Array.concat |
![]() ![]() ![]() |
Array.concat
Availability
Flash Player 5.
Usage
myArray
.concat(
value0,value1,...valueN
)
Parameters
value0,...valueN
Numbers, elements, or strings to be concatenated in a new array.
Returns
Nothing.
Description
Method; concatenates the elements specified in the parameters, if any, with the elements in myArray
, and creates a new array. If the value
parameters specify an array, the elements of that array are concatenated, rather than the array itself. The array myArray
is left unchanged.
Example
The following code concatenates two arrays.
alpha = new Array("a","b","c");
numeric = new Array(1,2,3);
alphaNumeric=alpha.concat(numeric);
trace(alphaNumeric);// creates array ["a","b","c",1,2,3]
The following code concatenates three arrays.
num1=[1,3,5];
num2=[2,4,6];
num3=[7,8,9];
nums=num1.concat(num2,num3)
trace(nums);// creates array [1,3,5,2,4,6,7,8,9]
Nested arrays are not flattened in the same way normal arrays are. The elements in a nested array are not broken into separate elements in array x
, as in the following example.
a = new Array ("a","b","c");
n = new Array(1, [2, 3], 4); // 2 and 3 are elements in a nested array x = a.concat(n); x[0] ="a"
x[1] ="b"
x[2] ="c"
x[3] = 1 x[4] = 2, 3 x[5] = 4
![]() ![]() ![]() |