Skip to content
Home Tutorials Roadmaps Courses Classroom Training Blog
Log in Join free
TypeScript Intermediate Free

Tuples

Lesson 7 of 17 · Arrays & Tuples 41%

Tuples are fixed-length arrays with specific types at each position.

Syntax

TYPESCRIPT
let person: [string, number] = ["John", 30];
let record: [number, string, boolean] = [1, "active", true];
Tuple Types
TYPESCRIPT
let person: [string, number] = ["Alice", 25];
console.log(person[0], person[1]);

function useState(initial: number): [number, (n: number) => void] {
    let value = initial;
    const setter = (n: number) => { value = n; };
    return [value, setter];
}

const [count, setCount] = useState(0);
console.log(count);

Practice

1
Exercise

Practice this concept.

Answer
Write the code as shown above.

Quick Quiz

1

What did you learn?

This covers the basics.

Choose an answer to continue.

Interview Questions

It is a fundamental TypeScript feature.

Up next

Union Types

Lesson 8 of 17 · Unions & Enums