Arrays and Tuples
An array type is written type[] or Array<type>. A tuple has a fixed length with a type per position. readonly arrays cannot be changed.
Example
const nums: number[] = [1, 2, 3];
nums.push(4);
const pair: [string, number] = ["Ada", 21];
const ro: readonly string[] = ["a", "b"];
console.log(nums, pair[0], ro.length);Result
[ 1, 2, 3, 4 ] Ada 2
Exercise
Declare an array of numbers.
const n: [] = [1, 2];
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.