 <p>Try something like this. It simply appends to the list instead of directly stating an index point. If you need to specify an index point, that is what dictionaries are for, so you should be using that instead of an array.</p> <pre><code>var aMainNav = ['b1', 'b2', 'b3']; var i = 0; while(i &lt; aMainNav.length){ var j = ++i; var item = $('.mainNav li:nth-child('+j+')')); aMainNav.push(item); i++; } </code></pre>