TypeScript Arrays & Tuples

Typed arrays, readonly arrays and tuples.

✍️ 3 exercises + code challenge in this lesson
  • Array: const names: string[] = ["Ali", "Sara"]; or Array<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]

Key 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

TypeScript
const scores: number[] = [72, 95, 88];
scores.push(64);

const user: [string, number] = ["Hina", 23];
const [name, age] = user;

console.log(scores.length, name, age);
Output
4 Hina 23
Free sign-in required · Google login available

TypeScript Arrays & Tuples Practice Exercises

Check what you learned in “TypeScript Arrays & Tuples”.

/ 3 solved
Fill in the blank

Declare an array of numbers.

const marks:  = [80, 90];
✓ Correct! Not quite. Try again.
Multiple choice

What is a tuple?

✓ Correct! Not quite. Try again.
Code challenge

Create a tuple pair: [string, number] = ["Ali", 25] and log both values separated by a space.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

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