Returns a new array comprised of this array joined with other array(s) and/or value(s).
| Method of Array | |
| Implemented in: | JavaScript 1.2, NES 3.0 |
| ECMA Version: | ECMA-262 |
concat creates a new array consisting of the elements in the this object on which it is called, followed in order by, for each argument, the elements of that argument (if the argument is an array) or the argument itself (if the argument is not an array).
concat does not alter this or any of the arrays provided as arguments but instead returns a "one level deep" copy that contains copies of the same elements combined from the original arrays. Elements of the original arrays are copied into the new array as follows:
concat copies object references into the new array. Both the original and new array refer to the same object. That is, if a referenced object is modified, the changes are visible to both the new and original arrays.
concat copies the values of strings and numbers into the new array.
Any operation on the new array will have no effect on the original arrays, and vice versa.
The following code concatenates two arrays:
var alpha = ["a", "b", "c"]; var numeric = [1, 2, 3]; // creates array ["a", "b", "c", 1, 2, 3]; alpha and numeric are unchanged var alphaNumeric = alpha.concat(numeric);
Page last modified 09:03, 6 Aug 2007 by Mgjbot