To create a two-dimensional array in TypeScript, we can simply use the syntax below:
index.ts52 chars2 lines
In this example, we have created a two-dimensional array called myArray
that contains three arrays, each of which contains two numbers. We have declared the type of the array to be number[][]
to indicate that it is a two-dimensional array of numbers.
To access a specific element in the array, we can use the indices of the element, like so:
index.ts41 chars2 lines
This will output the value at index 0 of the second nested array, which is 3.
gistlibby LogSnag