0

I want to combine part of a variable name with another variable to complete the full variable name. "Box + A2G[i]" would be the BoxA, BoxB, or BoxC variable.

var A2G = new Array("A","B","C");

var BoxA = new Array("apple","peach","grape");
var BoxB = new Array("volvo","GMC","Honda");
var BoxC = new Array("Bob","Susan","Mark");

for(i=0;i<A2G.length;i++) {

$("#row1").prepend('<div class="myfloat"> \
                            <div style="position:relative;height:100%;width:100%;"> \
                              <div class="cbox"> \
                                <div style="text-align:center;font-size:9px;"><u><b>Circuits</b></u><br' + Box + A2G[i] +'</div> \
                              </div> \
                              <div style="text-align:center">' + A2G[i] + '</div> \
                              <div id="' + A2G[i] + 'spot"></div> \
                            </div> \
                          </div>');
};
Jeight
  • 398
  • 1
  • 5
  • 14

1 Answers1

3

Your "Box" should be an object:

var Box = {
  A: ["apple", "peach", "grape"],
  B: ["volvo", "GMC", "Honda"],
  C: ["Bob", "Susan", "Mark"]
};

Then you can just use Box[ A2G[i] ].

Pointy
  • 405,095
  • 59
  • 585
  • 614