create two dimensional array in typescript

To create a two-dimensional array in TypeScript, we can simply use the syntax below:

index.ts
let myArray: number[][] = [[1, 2], [3, 4], [5, 6]];
52 chars
2 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.ts
console.log(myArray[1][0]); // Output: 3
41 chars
2 lines

This will output the value at index 0 of the second nested array, which is 3.

gistlibby LogSnag