Arrays and Tuples
Work with arrays and tuples in TypeScript.
Arrays and Tuples is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Arrays and Tuples
Welcome to the next lesson! In this lesson, we’ll explore how to work with arrays and tuples in TypeScript. These structures allow you to store multiple values in an organized way. Let’s dive in!

2
What Are Arrays?
An array is a collection of items stored in a single variable. In TypeScript, you can specify the type of elements in an array. Example:
Task: Create an array of your favorite numbers and log it to the console.
let numbers: number[] = [1, 2, 3, 4, 5];
let names: string[] = ["Alice", "Bob", "Charlie"];
console.log(numbers);
console.log(names);
3
Accessing Array Elements
You can access elements in an array using their index. Remember, array indexes start at 0:
Task: Try accessing different elements in an array and log them to the console.
let colors: string[] = ["red", "blue", "green"];
console.log(colors[0]); // Output: "red"
console.log(colors[2]); // Output: "green"
4
Common Array Methods
TypeScript arrays come with many useful methods. Here are some examples:
- push: Adds an element to the end of the array.
- pop: Removes the last element of the array.
- length: Returns the number of elements in the array.
Example:
Task: Experiment with array methods like push and pop.
let fruits: string[] = ["apple", "banana"];
fruits.push("cherry"); // Add "cherry"
console.log(fruits); // Output: ["apple", "banana", "cherry"]
fruits.pop(); // Remove "cherry"
console.log(fruits); // Output: ["apple", "banana"]
console.log(fruits.length); // Output: 2
5
What Are Tuples?
A tuple is a fixed-length array where each element can have a different type. Tuples are useful for grouping related data of different types. Example:
Task: Create a tuple to represent a student with a name and age.
let person: [string, number] = ["Alice", 30];
console.log(person[0]); // Output: "Alice"
console.log(person[1]); // Output: 30
6
Working with Tuples
Just like arrays, tuples support indexing and methods. However, their structure is fixed, and you can’t add extra elements without modifying the tuple type. Example:
Task: Define a tuple for a point in 2D space and log its values.
let coordinates: [number, number] = [10, 20];
console.log(`X: ${coordinates[0]}, Y: ${coordinates[1]}`);
// Attempting to add an extra element will result in an error
// coordinates.push(30); // Error: Tuple type '[number, number]' of fixed length 2
7
Using Arrays of Tuples
You can create an array of tuples to store multiple related data entries. Example:
Task: Create an array of tuples to store names and ages of your friends.
let students: [string, number][] = [
["Alice", 30],
["Bob", 25],
["Charlie", 35],
];
console.log(students[0]); // Output: ["Alice", 30]
console.log(students[1][1]); // Output: 25
8
Common Mistakes
Here are some common mistakes when working with arrays and tuples:
- Accessing elements outside the array’s bounds (results in
undefined). - Using the wrong type of data in arrays or tuples (causes errors in TypeScript).
- Attempting to change the structure of a tuple without updating its type.
Tip: Always specify types explicitly to avoid unexpected behavior!
9
let scores: number[] = [10, 20, 30];
console.log(scores.length);
10
Great Job!
Congratulations! You’ve learned how to use arrays and tuples in TypeScript to store and manage collections of data. These are essential tools for handling structured information in your programs. In the next lesson, we’ll explore union and intersection types to handle more complex scenarios. Let’s keep coding!

Frequently asked questions
Is the “Arrays and Tuples” lesson free?
Yes — the full text of “Arrays and Tuples” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Arrays and Tuples”?
Work with arrays and tuples in TypeScript. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Arrays and Tuples” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Arrays and Tuples
- Union and Intersection Types
- Enums
- Literal Types