# Matrices in javascript?



## redivivus (Mar 30, 2006)

Heya. Is it possible to simulate 2dimensional arrays (matrices) in javascript? I searched but couldnt even find out for sure if it was possible or not, let alone any guidance. One site used an array of arrays -- does anyone know if this works?

Thanks.


----------



## flytape8490 (Oct 7, 2003)

I'm sure it works considering you found a site that uses some. but how, i don't know


----------



## Shadow2531 (Apr 30, 2001)

What do you want to do with them?

Attached is an example that will help in creating and displaying them. It contains a bunch of extra stuff, but here's the important part;


```
function Matrix() {
    this.rows = new Array();
}
var m = new Matrix();
m.rows[0] = new Array( 1, 2, 3 );
m.rows[1] = new Array( 4, 5, 6 );
m.rows[2] = new Array( 7, 8, 9 );
```
In the attached file, you can see how you can access all the cells. You can use that info to make a function for mutliplying the matrix by another for example.


----------

