To iterate over a Two Dimensional Array in TypeScript, you can use nested loops.
In this example,
matrix
.const matrix: number[][] = [[0, 1, 2], [1, 2, 3], [2, 3, 4]];
for (let i = 0; i < matrix.length; i++) {
for (let j = 0; j < matrix[i].length; j++) {
console.log(matrix[i][j]);
}
}
0 1 2 1 2 3 2 3 4
In this example,
matrix
.const matrix: string[][] = [['Hello', 'World'], ['TypeScript', 'JavaScript']];
for (let i = 0; i < matrix.length; i++) {
for (let j = 0; j < matrix[i].length; j++) {
console.log(matrix[i][j]);
}
}
Hello World TypeScript JavaScript
In this tutorial, we learned How to Iterate over a Two Dimensional Array in TypeScript language with well detailed examples.