Javascript: Compile string based on multiple variable names
<p>This should be bone simple, and as usual, I'm probably overlooking something due to my less-than-thorough way of teaching myself code.  Hopefully this makes sense...</p>

<p>In a php loop, I have this:</p>

<pre><code>var key = &lt;?php echo json_encode($key); ?&gt;;
var id&lt;?php echo $key;?&gt; = &lt;?php echo json_encode($value['Claim']['id']); ?&gt;;
var point&lt;?php echo $key;?&gt; = &lt;?php echo json_encode($value['Claim']['point']); ?&gt;;
</code></pre>

<p>Which evaluates just as I want it.  So id2 equals whatever id2 is supposed to be, etc.</p>

<p>Then later I need to call those variables, like this:</p>

<pre><code>var takeurl = '/api/response.json?point='+ point + '&amp;id=' + id;
</code></pre>

<p>Except I want "point" and "id" to be the value of "point2" or "point4" or, in shorthand, point+key.</p>

<p>If I write it as </p>

<pre><code>var takeurl = '/api/response.json?point='+ point + key + '&amp;id=' + id;
</code></pre>

<p>it returns the value of "point" plus the value of "key," not the value of point2 or point3.</p>

<p>Then I realise that at the very beginning, when declaring those values, I shouldn't have to hit php all the time.  I should be able to do something like:</p>

<pre><code>var key = &lt;?php echo json_encode($key); ?&gt;;
var id[key] = &lt;?php echo json_encode($value['Claim']['id']); ?&gt;;
var point{"key"} = &lt;?php echo json_encode($value['Claim']['point']); ?&gt;;
</code></pre>

<p>And then create the new variable using the same convention.  I've read similar questions where the answer involves using arrays, but again, this is all in a larger php loop, so I don't see that fitting the situation here.  </p>

<p>Sorry, I hope this was clear.  I'm earning my username on this one.  Ideas?</p>

<p>EDITED TO ADD:
The problem is a little different than what I've explained above. My code is apparently pulling the values of the final variables that appear in the loop (as if I weren't defining them by a 'key' distinction at all, but just defining "point" five times). I fear I'm not making sense at all. Here's some code so you can see what's going on: codepad.org/ETX5dI6C</p>

<p>What I need is, for example, when clicking the fourth link on the page, for the values for id4 and point4 to be pulled.  Instead, no matter what link I click, it passes the variables for id5 and point5, which were defined last.  I don't get it?</p>
