Menu
Coddy logo textTech

What is a Tuple?

Part of the Introduction To TypeScript section of Coddy's JavaScript journey — lesson 15 of 73.

A tuple is an array with a fixed number of elements where the type of each element at each position is known and defined.

Think of a tuple as a container with labeled slots. Unlike a regular array where you might have string[] (any number of strings), a tuple specifies exactly how many elements it contains and what type each element should be.

// Regular array - any number of strings
let names: string[] = ["Alice", "Bob", "Charlie"];

// Tuple - exactly 2 elements: string, then number
let person: [string, number] = ["Alice", 25];

The key difference is that tuples have a fixed structure. The first element must always be a string, the second must always be a number, and there can be no third element.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction To TypeScript