Array.prototype.concat()
concat(...items) Returns:
array · Added in vES1 · Updated March 13, 2026 · Array Methods array concat merge immutable
The concat() method merges (concatenates) two or more arrays into a new array. It does not modify the original arrays — instead, it returns a brand new array containing all the elements.
Syntax
array.concat(...items)
items: Arrays or values to merge into the new array. Can be arrays or primitive values.- Returns: A new array containing all elements from the original array and all items passed as arguments.
TypeScript Signature
interface Array<T> {
concat(...items: (T | ConcatArray<T>)[Global_Objects::eval]): T[Global_Objects::eval];
}
interface ConcatArray<T> {
length: number;
[n: number]: T;
}
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
items | (T | ConcatArray<T>)[Global_Objects::eval] | — | Arrays or values to concatenate. Strings and numbers are flattened automatically. |
Examples
Basic Concatenation
const fruits = ["apple", "banana"];
const vegetables = ["carrot", "lettuce"];
const produce = fruits.concat(vegetables);
console.log(produce);
// ["apple", "banana", "carrot", "lettuce"]
// Original arrays remain unchanged
console.log(fruits);
// ["apple", "banana"]
console.log(vegetables);
// ["carrot", "lettuce"]
Concatenating Multiple Arrays
const arr1 = [1, 2];
const arr2 = [3, 4];
const arr3 = [5, 6];
const combined = arr1.concat(arr2, arr3);
console.log(combined);
// [1, 2, 3, 4, 5, 6]
// You can also use spread operator as alternative
const spreadCombined = [...arr1, ...arr2, ...arr3];
console.log(spreadCombined);
// [1, 2, 3, 4, 5, 6]
Concatenating Values and Arrays
const numbers = [1, 2];
// Mix arrays and primitive values
const mixed = numbers.concat([3, 4], 5, [6, 7]);
console.log(mixed);
// [1, 2, 3, 4, 5, 6, 7]
// Strings are flattened automatically
const letters = ["a", "b"].concat("c", ["d", "e"]);
console.log(letters);
// ["a", "b", "c", "d", "e"]
Deep Flattening with concat
// concat only flattens one level
const nested = [1, 2].concat([[3, 4], [5, 6]]);
console.log(nested);
// [1, 2, [3, 4], [5, 6]]
// For deep flattening, use flat()
const deepNested = [[1, 2], [[3, 4]]];
console.log(deepNested.flat(2));
// [1, 2, 3, 4]
Common Patterns
Copying an Array
const original = [1, 2, 3];
const copy = original.concat();
console.log(copy);
// [1, 2, 3]
console.log(copy === original);
// false
Prepending and Appending Elements
const nums = [3, 4, 5];
// Add elements at the start
const withStart = [1, 2].concat(nums);
console.log(withStart);
// [1, 2, 3, 4, 5]
// Add elements at the end
const withEnd = nums.concat([6, 7]);
console.log(withEnd);
// [3, 4, 5, 6, 7]
Performance Notes
concat()creates a new array, which has memory overhead- For large arrays or frequent concatenations, consider using spread operator
[...arr1, ...arr2]which has similar performance - If building an array incrementally in a loop, consider using
push()with spread orArray.from()for better performance
When to Use
- When you need a new merged array without modifying originals (immutable pattern)
- When concatenating multiple arrays in a single operation
- When you need to add primitive values alongside arrays
See Also
- array::push — Add elements to end of array
- array::flat — Flatten nested arrays
- array::from — Create array from iterable