Use variable contents in object?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bitslong
    New Member
    • Apr 2007
    • 7

    Use variable contents in object?

    Hi,
    I'm trying to use what is held in a variable to get to an object property:

    img_lib.section s is an array containing a varying number of strings - eg "Category1","Ca tegory2" etc

    img_lib.Categor y1 is an array that contains a varying number of strings

    In the second for statement I need to compare j to the length of the img_lib.* array as retrieved from img_lib.section s[i]

    I started with the code as shown below but I don't believe it works.

    Suggestions?

    Code:
    for (i=0; i<img_lib.sections.length; i++){
           alert("Primary Loop");
    	category=img_lib.sections[i];
    	cat_arr_str="img_lib.".category."[i]";
    	for(j=0; j<cat_arr_str.length; j++){
    		alert("Secondary Loop");
    	}
    				
    }
  • Bitslong
    New Member
    • Apr 2007
    • 7

    #2
    Solved it by making the second for statement:

    Code:
    for(j=0; j<img_lib[img_lib.sections[i]].length; j++){
     alert("Do stuff");
    }

    Comment

    Working...