logo

MultiDimensional Array (Javascript)

JavaScript: The Definitive Guide

This sample demostrations how to create an javascript array with more than one subscription range.

Introduction: The MultiDimensional Array

is zero based.  In the following example

the array range is [0..6][0..1].



Implementation:

var sDataArray=MultiDimensionalArray(7,2);

alert(sDataArray[0][0]);



Code

function MultiDimensionalArray(iRows,iCols)

{

var i;

var j;



	var a = new Array(iRows);



	for (i=0; i < iRows; i++) 

	{

		a[i] = new Array(iCols);

		for (j=0; j < iCols; j++) 

		{

			a[i][j] = "";

		}

	}

	return(a);

}

s