How to assign an object via a variable in Javascript?

Discussion in 'JavaScript' started by itblue, Oct 1, 2008.

  1. #1
    I have 1000 objects named from a_1 to a_1000 like this:

    a_1 = new Option("text1", "Val1");
    a_2 = new Option("text2", "Val2");
    ...
    a_1000 = new Option("text1000", "Val1000");
    Code (markup):
    Now I want to add all to an array named obj_array as the following codes:

    for(var i=1; i<=1000; i++){
        var obj_name =[B] "a_" + i[/B];
        obj_array[i] = obj_name;
    }
    Code (markup):
    Above codes doesn't work as I expect because obj_name is really a String. What I need is a reference to the object. Do you know how to solve this problem? Please help me.

    Thank you
     
    itblue, Oct 1, 2008 IP
  2. itblue

    itblue Banned

    Messages:
    698
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Anybody can help me please!
     
    itblue, Oct 1, 2008 IP