lundi 27 avril 2015

Javascript assigning values into Muti Dimensional array

Using Javascript, I need to create a matrix table that looks like the matrix below:

0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0

The following code, to me, seems like that should be correct, however when I try to output arr[0][1] etc... no value show. Did I do something wrong in the following code:

var address = [
"...",
"....",
".....",
"......"

];

var arr = [];

for (i = 0; i < address.length; i++) 
{ 
    for (j = 0; j < address.length; j++) 
    { 
        //alert(i + " " + j);
        if (i=j)
        {
            arr[i][j]=0;
        }
        else
        {
            arr[i][j]=1;
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire