- Array:
const names: string[] = ["Ali", "Sara"];orArray<string> readonly string[]cannot be changed.- A tuple is an array with a fixed length and a type for each position:
let point: [number, number] = [3, 4]; - Named tuples:
[x: number, y: number]
TypeScript Arrays & Tuples
Typed arrays, readonly arrays and tuples.
✍️ 3 exercises + code challenge in this lessonKey Takeaways: TypeScript Arrays & Tuples
Mastering TypeScript Arrays & Tuples helps you write clean and reliable TypeScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
TypeScript Arrays & Tuples Code Example
TypeScriptconst scores: number[] = [72, 95, 88];
scores.push(64);
const user: [string, number] = ["Hina", 23];
const [name, age] = user;
console.log(scores.length, name, age);
4 Hina 23
TypeScript Arrays & Tuples Practice Exercises
Check what you learned in “TypeScript Arrays & Tuples”.
Declare an array of numbers.
const marks: = [80, 90];
What is a tuple?
Create a tuple pair: [string, number] = ["Ali", 25] and log both values separated by a space.
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services