Learn
Arrays
Multi-dimensional Arrays

So far we’ve looked at string[] arrays, but we could also have arrays that only contain numbers (number[]) or booleans (boolean[]). In fact, we can make arrays of any type whatsoever. We can also declare multidimensional arrays: arrays of arrays (of some type).

let arr: string[][] = [['str1', 'str2'], ['more', 'strings']];

Think of the string[][] above as short for (string[])[], that is, an array where every element has type string[]. We’ll explore more complex array types in later lessons.

The empty array ([]) is compatible with any array type:

let names: string[] = []; // No type errors. let numbers: number[] = []; // No type errors. names.push('Isabella'); numbers.push(30);

Practice time!

Instructions

1.

Please provide type annotations for all the arrays provided in the // Multidimensional arrays: section.

Folder Icon

Take this course for free

Already have an account?