# JavaScript Program to find Matrix Addition

You are Here:

In the following example, we will add the two given matrices (two-dimensional arrays).

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 Addition</h1> <script> var i, j; var arr1 = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ]; var arr2 = [ [2, 2, 2], [2, 2, 2], [2, 2, 2] ]; var arr3 = [ [0, 0, 0], [0, 0, 0], [0, 0, 0], ]; document.write("Matrix A (3 x 3):<br>"); for(i=0; i<3; i++) { for(j=0; j<3; j++) document.write(arr1[i][j] +" "); document.write("<br>"); } document.write("Matrix B (3 x 3):<br>"); for(i=0; i<3; i++) { for(j=0; j<3; j++) document.write(arr2[i][j] +" "); document.write("<br>"); } document.write("Sum of Matrix:<br>"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { arr3[i][j] = arr1[i][j] + arr2[i][j]; document.write(arr3[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.