Use first.concat(second) to join arrays in TypeScript. It returns a new array, leaving the original arrays unchanged:
const first = [1, 2];
const second = [3, 4];
const combined = first.concat(second);
// [1, 2, 3, 4]
How to concatenate two or more arrays
Call concat() on the array whose elements should come first, then pass the other array or arrays as arguments:
As an Amazon Associate I earn from qualifying purchases.
const names = ["Ada", "Lin"];
const moreNames = ["Grace"];
const allNames = names.concat(moreNames);
// ["Ada", "Lin", "Grace"]
const values = ["a", "b"].concat(["c"], ["d", "e"]);
// ["a", "b", "c", "d", "e"]
The receiver’s elements appear first, followed by the elements of each array argument in order. You can also mix arrays with individual values:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchconst values = ["a", "b"].concat("c", ["d", "e"]);
// ["a", "b", "c", "d", "e"]
How concat() handles values and nested arrays
An array passed to concat() contributes its elements one level deep. A non-array value, such as a string or number, is appended as one element. It does not recursively flatten nested arrays:
#1 Best Overall
const nested = [[1]].concat([[2]]);
// [[1], [2]]
This is JavaScript’s Array.prototype.concat() behavior, which TypeScript code uses. See MDN’s concat() reference.
Does concat() change the original arrays?
No. concat() returns a new outer array and does not modify the receiver or array arguments. The copy is shallow: if the arrays contain objects or nested arrays, the result contains references to those same values, not independent copies. A change to a shared object can therefore be seen through both arrays. MDN documents the method’s copying behavior.
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
What TypeScript types does concat() produce?
For ordinary arrays, TypeScript infers a result type that can represent the elements being concatenated. If the call reports a type error, check the declared element types and the overload TypeScript selects: the arguments must match an available overload. Exact inference can vary with tuple declarations and TypeScript version, so confirm the type in the project and compiler version you use. See the TypeScript documentation on object and array types.
Free tools Windows power users keep installed
One-click scans. No signup required.
Accepting readonly arrays
ReadonlyArray<T> and readonly T[] describe arrays that cannot be mutated through that reference. Readonly types retain read operations but omit mutating array methods. This matters when a helper accepts readonly inputs: calling a mutating method on such a reference is not allowed by the type system. See TypeScript’s ReadonlyArray guidance.
Keeping tuple types in a custom helper
For a helper that combines readonly tuples and preserves their tuple information, TypeScript 4.0’s release notes show a variadic tuple pattern using spread syntax:
type Arr = readonly any[];
function concat<T extends Arr, U extends Arr>(arr1: T, arr2: U): [...T, ...U] {
return [...arr1, ...arr2];
}
This is a custom helper, not a change to the runtime behavior of Array.prototype.concat(). When a spread type has an unknown length, the resulting tuple becomes unbounded from that point. See the TypeScript 4.0 variadic tuple release notes.
Quick Recap
Best Value
Common mistakes
- Expecting the first array to change: use the returned array;
concat()leaves its inputs unchanged. - Expecting a deep copy: nested arrays and objects remain shared references.
- Expecting recursive flattening: array arguments contribute elements only one level deep.
- Assuming a type error means different runtime behavior: inspect the declared element types and overload matching.
- Assuming arbitrary arrays always yield an exact tuple type: tuple inference depends on the types involved; unknown-length spreads can produce unbounded tuples.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools




