Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
A100213: Implementing Multi-dimensional Arrays in JavaScript.
Unlike VBScript, JavaScript does not natively support multi-dimensional arrays. However, it is possible to simulate a multi-dimensional array by creating an array of arrays. This brief article demonstrates the technique.
The following code snippet creates a "2-dimensional" array and populates it with two "rows" and three "columns" of data:
JavaScript code:
<script type="text/javascript">
// Create the array
var Room = new Array();
Room[0] = new Array();
Room[1] = new Array();
// Populate the array
Room[0][0] = "white";
Room[0][1] = "red";
Room[0][2] = "blue";
Room[1][0] = "black";
Room[1][1] = "yellow";
Room[1][2] = "purple";
// Iterate the array
for (var i=0; i<2; i++)
for (var j=0; j<3; j++)
document.write(Room[i][j] + "<br>")
</script>
Browser output:
white
red
blue
black
yellow
purple
This concept is easily extended to simulate three- and higher- dimensional arrays.
The Guru
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information
knoxville photographer
knoxville wedding photographer