5*5 matrix in Javascript,Unityscript(Multidimensional Array)

http://stackoverflow.com/questions/10021847/for-loop-in-multidimensional-javascript-array

http://jsfiddle.net/TRR4n/

My code:

//To show the array value
https://jsfiddle.net/zakilive/6yrx1opj/1/

/*
Author:Syed Ahmed Zaki
www.zakilive.com
*/

var array = [
 ["a", "b", "c", "d", "e"],
 ["f", "g", "h", "i", "j"],    
 ["k", "l", "m", "n", "o"],
 ["p", "q", "r", "s", "t"],
 ["w", "v", "x", "y", "z"],
];

for(var i = 0; i < array.length; i++) {
    var matrix = array[i];
    for(var j = 0; j < matrix.length; j++) {
        print("matrix[" + i + "][" + j + "] = " + matrix[j]);
    }
}

//To print the array

http://www.trans4mind.com/personal_development/JavaScript/Array2D.htm
http://www.javascripter.net/faq/twodimensional.htm
http://www.plus2net.com/javascript_tutorial/array-two-dimension.php

/*
Author:Syed Ahmed Zaki
www.zakilive.com
*/

//Declaring the values
var matrix = new Array(5);

matrix[0]=new Array(5);
matrix[0][0]="A";
matrix[0][1]="B";
matrix[0][2]="C";
matrix[0][3]="D";
matrix[0][4]="E";


matrix[1]=new Array(5);
matrix[1][0]="F";
matrix[1][1]="G";
matrix[1][2]="H";
matrix[1][3]="I";
matrix[1][4]="J";

matrix[2]=new Array(5);
matrix[2][0]="K";
matrix[2][1]="L";
matrix[2][2]="M";
matrix[2][3]="N";
matrix[2][4]="O";

matrix[3]=new Array(5);
matrix[3][0]="P";
matrix[3][1]="Q";
matrix[3][2]="R";
matrix[3][3]="S";
matrix[3][4]="T";

matrix[4]=new Array(5);
matrix[4][0]="U";
matrix[4][1]="V";
matrix[4][2]="W";
matrix[4][3]="X";
matrix[4][4]="Y";

//Printing the values

for(var i=0;i<5;i++)
{
for(var j=0lj<5;j++)
{
print(matrix[i][j]\n);
}
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *