Tuples: Fixed-Length Typed Arrays
Define tuples for structured data with known positions.
Welcome
Tuples are arrays with a fixed number of elements where each position has a specific type. They are perfect for structured data like coordinates or key-value pairs.
Defining a Tuple
A tuple type lists the type of each element in order. The length is fixed and each position must hold the declared type.
const point: [number, number] = [10, 20];
const entry: [string, number] = ['age', 25];All lessons in this course
- Typed Arrays: T[] and Array
- Readonly Arrays and Immutable Data
- Tuples: Fixed-Length Typed Arrays
- Enums: Numeric and String Constants