JavaScript MultiDimensional Array read array name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jezternz
    New Member
    • Jan 2008
    • 145

    JavaScript MultiDimensional Array read array name

    First of all I am open to any suggestions and advice. If a javscript multidimensiona l 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 multidimensiona l 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><t d colspan=2>1st dimension name</td></tr>
    <tr><td>Secon d 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)

    Code:
    var css_properties = new Array();
    
    var background = new Array;
    	css_properties[0] = background;
    var border = new Array;
    	css_properties[1] = border;
    
    var background_attachment = new Array();
    css_properties[0][0] = background_attachment;
    	css_properties[0][0][0] = 'scroll';
    	css_properties[0][0][1] = 'fixed';	
    var background_color = new Array();
    css_properties[0][1] = background_color;
    	css_properties[0][1][0] = 'custom';
    	css_properties[0][1][1] = 'transparent';
    var background_image = new Array();
    css_properties[0][2] = background_image;
    	css_properties[0][2][0] = 'custom';
    	css_properties[0][2][1] = 'none';
    
    
    var border_top_color = new Array();
    css_properties[1][0] = border_top_color;
    	css_properties[1][0][1] = 'custom';
    	css_properties[1][0][0] = 'transparent';
    var border_top_style = new Array();
    css_properties[1][1] = border_top_style;
    	css_properties[1][1][0] = 'none';
    	css_properties[1][1][1] = 'hidden';
    	css_properties[1][1][2] = 'dotted';
    	css_properties[1][1][3] = 'dashed';
    	css_properties[1][1][4] = 'solid';
    	css_properties[1][1][5] = 'double';
    	css_properties[1][1][6] = 'groove';
    	css_properties[1][1][7] = 'ridge';
    	css_properties[1][1][8] = 'inset';
    	css_properties[1][1][9] = 'outset';
    var border_top_width = new Array();
    css_properties[1][2] = border_top_width;
    	css_properties[1][2][0] = 'custom';
    	css_properties[1][2][1] = 'thin';
    	css_properties[1][2][2] = 'medium';
    	css_properties[1][2][3] = 'thick';
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    There is nothing called name in such case.

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

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

    For the solution of the question, you can do this thing though:[code=javascript]//var border_top_colo r = new Array();
    //css_properties[1][0] = border_top_colo r;
    css_properties[1][0]['name'] = 'border_top_col or';
    css_properties[1][0][1] = 'custom';
    css_properties[1][0][0] = 'transparent';[/code]
    And use the index name where required.

    Regards,
    Harpreet

    Comment

    • Jezternz
      New Member
      • Jan 2008
      • 145

      #3
      so this would be better then an xml file? (faster)
      Thanks for your help, Much apreciated.

      Josh

      Comment

      • pronerd
        Recognized Expert Contributor
        • Nov 2006
        • 392

        #4
        Originally posted by Jezternz
        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.

        Comment

        • Jezternz
          New Member
          • Jan 2008
          • 145

          #5
          Ok, cheerz. Array it is!

          Comment

          Working...