Learn

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.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?