October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Concatenate Arrays in TypeScript with concat()

Use Array.concat() in TypeScript to combine arrays into a new array without changing the inputs. Learn how values, nested arrays, readonly types, and tuples behave.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const 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:

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 Programming Language - Software Engineer & Coder T-Shirt
  • 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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.