JS Multidimensional Array


Multidimensional array has more than 1 dimension, such as 2 dimensional array, 3 dimensional array etc.

Define a dimensional array once at initialization.

var arr = [
	[2,4],
	[20,40],
	[200,400]
];
arr[1][1];  //40


Define a dimensional array dynamically.

var arr= new Array();
arr[0] = new Array();
	arr[0][0] = 1;
	arr[0][1] = 2;
arr[1] = new Array();
	arr[1][0] = 3;
	arr[1][1] = 4;
arr[1][0];  //3


Define a dimensional associative array dynamically.

var efs = new Array();
efs["em"]=new Array();
	efs["em"]["em"] = 1;
	efs["em"]["g5"] = 1899.10078;
	efs["em"]["xy"] = 1000;
	efs["em"]["d5"] = 1;
efs["g5"]=new Array();
	efs["g5"]["em"]=0.0005;
	efs["g5"]["g5"]=1;
	efs["g5"]["xy"]=0.5265;
	efs["g5"]["d5"]=0.0005265;
efs["em"]["xy"]; //1000


endmemo.com © 2024  | Terms of Use | Privacy | Home