By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,536 Members | 1,800 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,536 IT Pros & Developers. It's quick & easy.

JavaScript MultiDimensional Array read array name

Jezternz
100+
P: 145
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it would be slower for jsp to handel.

Okay here is an example of my multidimensional array (only part of it)(bottom of the post). It works fine I can call any of the 3rd dimension without trouble.

Now How would I go about printing something like this from the array:

[HTML]
<table><tr><td colspan=2>1st dimension name</td></tr>
<tr><td>Second Dimension name</td><td>Third Dimension Property</td></tr></table>
[/HTML]

I guess what Im really asking is how to print the name of an array.
Obviously I can access the third dimension by just acessing array[0][0][0] however when I try return array[0][0] it just returns all the contents of [0][0] and not the name of [0][0] itself.

Not sure if I made that clear or not. Can I retrieve an array name somehow? (an array that is inside another arry)

Expand|Select|Wrap|Line Numbers
  1. var css_properties = new Array();
  2.  
  3. var background = new Array;
  4.     css_properties[0] = background;
  5. var border = new Array;
  6.     css_properties[1] = border;
  7.  
  8. var background_attachment = new Array();
  9. css_properties[0][0] = background_attachment;
  10.     css_properties[0][0][0] = 'scroll';
  11.     css_properties[0][0][1] = 'fixed';    
  12. var background_color = new Array();
  13. css_properties[0][1] = background_color;
  14.     css_properties[0][1][0] = 'custom';
  15.     css_properties[0][1][1] = 'transparent';
  16. var background_image = new Array();
  17. css_properties[0][2] = background_image;
  18.     css_properties[0][2][0] = 'custom';
  19.     css_properties[0][2][1] = 'none';
  20.  
  21.  
  22. var border_top_color = new Array();
  23. css_properties[1][0] = border_top_color;
  24.     css_properties[1][0][1] = 'custom';
  25.     css_properties[1][0][0] = 'transparent';
  26. var border_top_style = new Array();
  27. css_properties[1][1] = border_top_style;
  28.     css_properties[1][1][0] = 'none';
  29.     css_properties[1][1][1] = 'hidden';
  30.     css_properties[1][1][2] = 'dotted';
  31.     css_properties[1][1][3] = 'dashed';
  32.     css_properties[1][1][4] = 'solid';
  33.     css_properties[1][1][5] = 'double';
  34.     css_properties[1][1][6] = 'groove';
  35.     css_properties[1][1][7] = 'ridge';
  36.     css_properties[1][1][8] = 'inset';
  37.     css_properties[1][1][9] = 'outset';
  38. var border_top_width = new Array();
  39. css_properties[1][2] = border_top_width;
  40.     css_properties[1][2][0] = 'custom';
  41.     css_properties[1][2][1] = 'thin';
  42.     css_properties[1][2][2] = 'medium';
  43.     css_properties[1][2][3] = 'thick';
  44.  
  45.  
Apr 2 '08 #1
Share this Question
Share on Google+
4 Replies


hsriat
Expert 100+
P: 1,654
There is nothing called name in such case.

I mean first you write:
var border_top_color = new Array();
Here you declared the array
css_properties[1][0] = border_top_color;
Here you copied the array to the css_properties[1][0]. Name of the array , border_top_color is not retrieved anywhere.

Don't confuse the XML format to be similar to a multidimensional Array.

For the solution of the question, you can do this thing though:
Expand|Select|Wrap|Line Numbers
  1. //var border_top_color = new Array();
  2. //css_properties[1][0] = border_top_color;
  3.     css_properties[1][0]['name'] = 'border_top_color';
  4.     css_properties[1][0][1] = 'custom';
  5.     css_properties[1][0][0] = 'transparent';
And use the index name where required.

Regards,
Harpreet
Apr 2 '08 #2

Jezternz
100+
P: 145
so this would be better then an xml file? (faster)
Thanks for your help, Much apreciated.

Josh
Apr 2 '08 #3

Expert 100+
P: 392
so this would be better then an xml file? (faster)
Unless it is a huge amount of data, it is not going to make a difference.
Apr 2 '08 #4

Jezternz
100+
P: 145
Ok, cheerz. Array it is!
Apr 3 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.