Use push() to add values to the end of a mutable TypeScript array, or unshift() to add them at the beginning. If you need to keep the original array unchanged—or your input is typed as readonly—create a new array with spread syntax or concat().
Append elements to the end with push()
push() adds one or more values to the end of the existing array. It changes that array and returns its new length, not a replacement array.
const names: string[] = ["Ada", "Lin"];
names.push("Grace");
// names is now ["Ada", "Lin", "Grace"]
const newLength = names.push("Edsger");
The Handbook describes the method signature as push(...items: Type[]): number; the return value is the array’s new length. TypeScript Handbook: Interfaces
Add several values
Pass each value as a separate argument:
names.push("Katherine", "Alan");
To append the contents of another array, spread its elements into the call:
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
const moreNames: string[] = ["Katherine", "Alan"];
names.push(...moreNames);
For function-call spread, TypeScript must be able to type the arguments. A tuple such as one inferred with as const preserves fixed positions; the Handbook also documents rest parameters as a relevant pattern. If your project targets older runtimes, check its TypeScript configuration: supporting iteration during downlevel compilation can require downlevelIteration. TypeScript Handbook: More on Functions
Insert elements at the beginning with unshift()
Call unshift() to add values before the current first element. The existing items remain after the inserted values, and the array is mutated.
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
const names: string[] = ["Ada", "Lin"];
names.unshift("Barbara");
// names is now ["Barbara", "Ada", "Lin"]
MDN: Array.prototype.push() describes the related array operations, including unshift().
Create an appended array without changing the original
If another part of your program should continue to see the original contents, build a new array instead of calling a mutating method.
const original = [1, 2, 3];
const withFour = [...original, 4];
const alsoWithFour = original.concat(4);
Both examples produce a new array and leave original intact. Use spread for a concise expression, or concat() when it better fits the surrounding code. To combine two arrays, use [...first, ...second] or first.concat(second).
Choose the method that matches your intent
| Need | Approach | Effect |
|---|---|---|
| Append to a mutable array | array.push(value) |
Changes the existing array and returns its new length. |
| Add at the beginning | array.unshift(value) |
Changes the existing array by inserting at the front. |
| Append while keeping the source unchanged | [...array, value] or array.concat(value) |
Creates a new array. |
| Combine arrays into a new result | [...first, ...second] or first.concat(second) |
Creates an array containing the elements from both inputs. TypeScript 4.0 documented typed variadic tuple concatenation for preserving tuple structure in applicable cases. |
| Accept an array callers may share without mutating it | readonly T[] or ReadonlyArray<T> |
Prevents mutating methods from being called through that TypeScript reference. |
The TypeScript 4.0 release notes explain variadic tuple types and concatenation: TypeScript 4.0 release notes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Append to a readonly input by returning a new array
A function can accept a readonly array to make clear that it will not mutate the caller’s input, then return a mutable array with the additional item:
function withItem<T>(items: readonly T[], item: T): T[] {
return [...items, item];
}
TypeScript’s readonly array type removes mutating methods such as push(). It also does not assign to a mutable array variable without an assertion. Prefer constructing a fresh array, as above, instead of asserting away the readonly constraint. The Handbook describes ReadonlyArray as “a special type that describes arrays that shouldn’t be changed.” TypeScript Handbook: Object Types
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesBest Value
What readonly does—and does not—guarantee
readonly is a TypeScript compile-time constraint, not a runtime freeze. It prevents mutation through a reference typed as readonly, but it does not stop another alias to the same JavaScript array from changing its contents. If the program requires runtime immutability, it needs a separate runtime design.
Quick Recap
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.




