Return to Kroll Design home page

JavaScript Tutorials

 
« Return

multi-dimensional numbered arrays

Multi-dimension arrays are arrays where each element is itself an array.

Code:

<script type="text/javascript">
//<![CDATA[
var floss = new Array(); floss[0] = 12; floss[1] = 4.99; floss[2] = 345; var toothbrush = new Array(); toothbrush[0] = 203; toothbrush[1] = 2.77; toothbrush[2] = 2416; var toothpaste = new Array(); toothpaste[0] = 89; toothpaste[1] = 1.43; toothpaste[2] = 968; var items = new Array(); items[0] = floss; items[1] = new Array(); items[1] = toothbrush; items[2] = new Array(); items[2] = toothpaste; for (i=0; i<items.length; i++) { for (j=0; j<3; j++) { document.write("items[", i, "][", j, "] : ", items[i][j], "<br>"); } document.write("<br>"); } //]]> </script>

Output:



 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM