Creating Dynamic variables from json response
<p>My JSON response looks like this :</p>

<pre><code>{"sample":[{"id":"2","name":"branch name"},{"id":"3","name":"branch name 2"}]}
</code></pre>

<p>My function looks like this :</p>

<pre><code>function getJSONObjects(){
        $.getJSON("http://localhost/api/branches",
        function(data){
          $.each(data.sample, function(i,item){
           var loc = "branch";
           eval("var " + loc + item.id + "=123;");
           alert(loc + item.id);
          });
        });
 }
</code></pre>

<p>The idea is to create <code>branch + id</code> object so I can do something with it(create marker on a map), so I tried to assign it any value to see if this was working. </p>

<p>I wanted both <code>branch2</code> and <code>branch3</code> to alert <code>123</code> so I have something to start with. But currently this alerts branch2 and branch3 instead of 123. </p>

<p>I have little experience with creating dynamic variables/objects can someone tell me what I'm doing wrong or maybe another approach towards solving this? </p>
