Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Y = New Array()
al-rafideen
post Dec 12 2007, 05:49 PM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 5
Joined: 14-October 07
From: uk
Member No.: 25,509



Hi,
I have no problem with one dimension Array. For example:
Y = new Array();
Y[0] = smith;
Y[1] = john;
..
..

My problem is with two dimension Array. For example:
Y[0,0] = smith;
Y[0,1] = john;
..
..
Do you agree to define Y = new Array() with two dimension Array.
Thank you for your help in this matter.
Go to the top of the page
 
+Quote Post
Jeigh
post Dec 12 2007, 10:16 PM
Post #2


Whitest Black Mage
Group Icon

Group: [MODERATOR]
Posts: 1,322
Joined: 20-May 05
From: NB, Canada
Member No.: 5,281



As far as I know (I may be wrong, I don't do a lot of javascript work) there are not true 2d arrays in javascript. You can, however, declare one array and then declare elements within that array as arrays which in effect is a multi-dimensional array. The site at http://www.javascriptkit.com/javatutors/twoarray1.shtml can show you an example and I found a bunch more just by quickly googling for '2d arrays in javascript'. It will likely take some playing around but if its important to your design I'm sure you can get something working that will be equivalent to having a 2 dimensional array.
Go to the top of the page
 
+Quote Post
kelvinmaki
post Dec 13 2007, 03:06 PM
Post #3


Advanced Member
Group Icon

Group: Members
Posts: 170
Joined: 30-July 07
Member No.: 23,704



Actually declare Y = new Array() is for the top level of the array, not a 2D array. So afterwhich you've declared that, you need to declare another array inside of Y. So like,

Y = new Array();
Y[0] = new Array();
Y[1] = new Array();

Then you are allow to put data into Y[0] array. eg.

Y[0][0] = smith;
Y[0][1] = smith2;
Y[1][0] = john;
Y[1][1] = john2;

Now then you'll have a 2D array. I've gotten error not declaring new Array() for both cases. Hope this help. Cheers
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Array Sorting(21)
  2. Help Needed With MySQL_fetch-array() Error(3)
  3. MySQL: Help Needed With MySQL_fetch_array() Error(7)
  4. Array Of <divs> In Another <div> Tag(2)
  5. Passing Select List As An Assoc. Array(1)
  6. Raid 1 Array(6)
  7. Day_sort()(1)
  8. OSCommerce Errors(5)


 



- Lo-Fi Version Time is now: 5th September 2008 - 11:09 AM