Use array value as variable name
<p>I need to use jQuery's keyup function to take the value from input html form elements and display said values in a div elsewhere.</p>

<p>The working code looks as follows:</p>

<pre><code>$('#name').keyup(function() {
    var name = $(this).val();
    $('#name-in-document').html(name);
});
</code></pre>

<p>Since I have many identical instances of the above code block, I'd like to use a for loop to loop through an array of values. The catch is the name of the variable in the second line</p>

<pre><code>var name = $(this).val();   
</code></pre>

<p>would come from the array.</p>

<p>I have tried the following loop, which does not work because (as I understand it) a Javascript variable cannot be named an array value:</p>

<pre><code>var inputsArray = ["phone", "name", "address"];

for (var i = 0; i &lt; inputsArray.length; i++) {

    $("#"+inputsArray[i]).keyup(function() {

    var inputsArray[i] = $(this).val();
    $("#"+inputsArray[i]+"-in-document").html(inputsArray[i]);

    })
</code></pre>

<p>};</p>

<p>So I have two questions:</p>

<ol>
<li>Is it true that I cannot use the array values to create a variable in the for loop?</li>
<li>Is there an alternate way to accomplish the same thing (getting the variable names from the array) that might work?</li>
</ol>

<p>I am just beginning JavaScript and really appreciate any insight. Thank you!</p>
