 <p>A few quick notes:</p> <ol> <li><p>Please don’t use <code>eval()</code>. There are very, very few cases where it’s needed, and it has performance and security implications.</p></li> <li><p>You’ve discovered that JavaScript doesn’t have “variable variables” (the ability to get or set a variable by name), which is why you had to resort to <code>eval()</code>. When you need to look something up out of a set, don’t use a bunch of numbered variables. Try an array or an object instead.</p></li> <li><p>Objects in JavaScript don’t get copied when you assign them to variables. The line</p> <pre><code>var arrayExtended = arrayGiven; </code></pre> <p>doesn't make a copy of <code>arrayGiven</code> — <code>arrayExtended</code> ends up being a variable which points at the same array. So, when you change something in <code>arrayExtended</code>, it also changes it in <code>arrayGiven</code>. If you need to copy an array in JavaScript, use <code>.slice()</code> with no arguments:</p> <pre><code>var arrayExtended = arrayGiven.slice(); </code></pre> <p>Some other things in JavaScript, like objects, are trickier to copy.</p></li> <li><p>What are you trying to do here? (<code>mainArray</code> is already an array) This is going to create a string which is a “[”, followed by the string representation of <code>mainArray</code> (each item in the array separated by commas), followed by “]”. Slimbox won’t know what to do with it.</p> <pre><code>jQuery.slimbox("[" + mainArray + "]",startAtImage); </code></pre> <p>If you do want to wrap something in an array, just put brackets around it like you did up above:</p> <pre><code>[mainArray]; </code></pre></li> </ol> <hr> <p>I think your main problem is <code>"[" + mainArray + "]"</code>. With those tips, you should be able to make your code work (and, without <code>eval()</code>). But, I want to show you my approach to this problem too. It’s below.</p> <p>I’m storing the names and descriptions of all the images in an array. Because arrays in JavaScript (and a lot of other programming languages) start at 0 instead of one, I subtracted one from all the image numbers in the arrays that specify the order.</p> <pre><code>var album = "summer", images = [ [ { name: "1", description: "Description #1" }, { name: "4", description: "Description #4" }, { name: "5", description: "Description #5" } ], [ { name: "2", description: "Description #2" }, { name: "6", description: "Description #6" } ], [ { name: "3", description: "Description #3" } ] ], order = [0, 2, 1], startAtImage = 0, slimboxImages = Array.prototype.concat.apply([], order.map(function(id){ return images[id]; })) .map(function(image){ return [ 'img/' + album + '/' + image.name + '.jpg', image.description]; }); jQuery.slimbox(slimboxImages, startAtImage); </code></pre>