# JavaScript Program to find Matrix Transpose

You are Here:

## Find Matrix Transpose

In the following example, we will transpose the given matrix (two-dimensional array).

Note: In Javascript, you have to initialize the two dimensional array before using it, because it is technically impossible to create a 2d array in javascript.

### Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <h1>JS Matrix Transpose</h1> <script> var i, j, n; var arr = [ [1, 1, 1], [2, 2, 2], [3, 3, 3] ]; document.write("Matrix A (3 x 3):<br>"); for(i=0; i<3; i++) { for(j=0; j<3; j++) document.write(arr[i][j] +" "); document.write("<br>"); } for(i=0; i<3; i++) { for(j=i+1; j<3; j++) { n = arr[i][j]; arr[i][j] = arr[j][i]; arr[j][i] = n; } } document.write("Transposed Matrix:<br>"); for(i=0; i<3; i++) { for(j=0; j<3; j++) document.write(arr[i][j] +" "); document.write("<br>"); } </script> </body> </html>

## Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.