TypeScript Multidimensional Arrays - TypeScript

What is TypeScript - Multidimensional Arrays?

An array element can reference another array for its value. Such arrays are called as multidimensional arrays. TypeScript supports the concept of multi-dimensional arrays. The simplest form of a multi-dimensional array is a two-dimensional array.

Declaring a Two-Dimensional array

Accessing a Two-Dimensional array element

The following example better explains this concept.

Example

The above example initially declares an array with 2 elements. Each of these elements refer to another array having 3 elements. The pictorial representation of the above array is given below.

TypeScript  Multidimensional Arrays

Multidimensional Arrays

While referring to an array element here, the subscript of the initial array element must be followed by the subscript of the referenced array element. This is illustrated in the code.

On compiling, it will generate following JavaScript code.

The output of the above code is as follows −

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

TypeScript Topics