dynamically name varibles in javascript
<p>How can i condense this into a loop and name the variables dynamically?<br/><br/>
this works</p>

<pre><code>var aMainNav = ['b1', 'b2', 'b3'];
aMainNav[0] = $('.mainNav li:nth-child(1)');
aMainNav[1] = $('.mainNav li:nth-child(2)');
aMainNav[2] = $('.mainNav li:nth-child(3)');
</code></pre>

<p>this doesnt</p>

<pre><code>var aMainNav = ['b1', 'b2', 'b3'];
var i = 0;
while(i &lt; aMainNav.length){
    var j = i++;
    eval(aMainNav[i] = $('.mainNav li:nth-child('+j+')'));
    i++;
}
</code></pre>

<p>and the button clicks</p>

<pre><code>aMainNav[0].click(function(){
    myLocation=='abc'?top.location.href='https://mydomain.com?var=1':window.location.href='./';
    return false;
});
aMainNav[1].click(function(){
    myLocation=='abc'?top.location.href='https://mydomain.com?var=2':window.location.href='./';
    return false;
});
aMainNav[2].click(function(){
    myLocation=='abc'?top.location.href='https://mydomain.com?var=3':window.location.href='./';
    return false;
});
</code></pre>
