Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multi-dimensional arrays

Status
Not open for further replies.

ndogg

Programmer
Feb 7, 2000
156
US
I was wondering if multi-dimensional arrays are possible in JavaScript like they are in other languages.
 
Hmmm...not sure...have you tried anything in an attempt to implement one? <p>-Robherc<br><a href=mailto:robherc@netzero.net>robherc@netzero.net</a><br><a href= > </a><br>*nix installation & program collector/reseller. Contact me if you think you've got one that I don't :)
 
no. but you can have an array of arrays that all contain arrays and so on.
 
Following Horrid:<br>
Javascript's matJ = new Array(new Array(), new Array()) acts similar to VB's dim matV(2,dim2) but is more flexible in that the Javascript's matJ &quot;rows&quot; need not have the same length. Get the entry in the second row, third column of matJ by var x = matJ[1][2] (unfortunately, indexing starts at 0). In the following code<br>
<br>
&lt;script language=&quot;JavaScript&quot;&gt;<br>
matJ = new Array(new Array(1,2,3,4,5), new Array(11,12,13,14,15,16))<br>
var x = matJ[1][2]<br>
alert('x is ' + x)<br>
&lt;/script&gt;<br>
<br>
the alert reports &quot;x is 13&quot;<br>

 
you could also set up a for loop:<br>
<br>
theArray = new Array(99);<br>
for (i=0; i&lt;theArray.length; i++){<br>
theArray<i>=new Array();}<br>
<br>
then refrence like:<br>
theArray[x][x]<br>
<br>
once again, you could do a 3-d array in a simmilar way:<br>
<br>
theArray = new Array(99);<br>
<br>
for (i=0; i&lt;theArray.length; i++){<br>
theArray<i>=new Array(99);<br>
for (j=0; j&lt;theArray<i>.length; i++){<br>
theArray<i>[j]=new Array(99);}}<br>
<br>
--not sure if the 3-d thing works, but if so, then you can have 2,000-d arrays!!!--(but why would you want that???) <p>theEclipse<br><a href=mailto: > </a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>
 
I already figured it out and I do use a loop to create one. The reason for doing so is if I were to have a viewer input a large text document and I would definitely need more than 99 arrays. Does anyone know if the old way of creating arrays has this limit?<br>
<p>REH<br><a href=mailto:hawkdogg@crosswinds.net>hawkdogg@crosswinds.net</a><br><a href= by Linux</a><br>Learn Linux and Leave out the Windows :)
 
Yes, it does. ALL javascript arrays have the 99 slot limit, if you excede the 99 slots limit, you will get a &quot;stack overflow at line ...&quot;<br>
<br>
<p>theEclipse<br><a href=mailto: > </a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top