title: How to avoid eval() when looping through array?
body: <p>I am working with Greensock animation library and when building a sequential animation (where one thing ends and the next starts right away) you have to enter it like this:</p>
  
  <pre><code>childTL.to($box, 1, {x:50,y:0})
         .to($box, 1, {x:50,y:50})
         .to($box, 1, {x:-50,y:50})
         .to($box, 1, {x:-50,y:0});  
  </code></pre>
  
  <p>The issue I have is that I am storing all the things in a database or as variables and so need to build things incrementally using for loops.</p>
  
  <p>What I want is something like this:</p>
  
  <pre><code>var animation = {
    "name": "movearound",
    "sequence": [{
      "duration": "1",
      "vars": {
        "x": "50",
        "y": "0"
      }
    }, {
      "duration": "1",
      "vars": {
        "x": "50",
        "y": "0"
      }
    }, {
      "duration": "1",
      "vars": {
        "x": "50",
        "y": "0"
      }
    }, {
      "duration": "1",
      "vars": {
        "x": "50",
        "y": "0"
      }
    }]
  }
  target = $(".target123")
  childTL = new TimelineLite{onUpdate: updateSlider});
  
  for (S = 0; S &lt; animatelayers.sequence.length; S++) {
    duration = animatelayers.sequence[S]["duration"];
    sequence = animatelayers.sequence[S]["vars"];
    if (S == 0) {
  
      childTL.to(target, duration, sequence)
    } else {
      .to(".target", duration, sequence);
    }
  }
  </code></pre>
  
  <p>I know I could do it with concatenating strings together and then do an eval() on it, but is there a way to do it without?</p>
  
  <p>Edit for why I am talking about eval():</p>
  
  <p>I guess the trouble I have is how picky Greensock is when it comes to things coming in as strings vs objects - for example you can use <code>$("#target")</code> in the .to(), but you can't use it if you define it as a variable first <code>var target = $("#target");</code> and then <code>childTL.to(target, 1, {x:50,y:0})</code> would fail, but if you do it as <code>var target = "#target"</code> it would work. So in the past I had created it all exactly like Greensock wanted as a string, and then used eval(). While I can keep doing that, I prefer to look for better ways of accomplishing things.</p>