title: Dynamically define variable name and assigning value in Google Apps Script
body: <p>I`m writing a script to generate a form in Google Apps Script.</p>
  
  <p>The idea is, that the user should select his/her name from a dropdown list, and then be transferred to the question block for him/her.</p>
  
  <p>Although the questions are the same, there are slight changes in the choices if the dropdowns for some of the questions.</p>
  
  <p>I have an array with the names of the users, and I've defined the questions for every single user.
  This is not ideal, as if there is any change in the questions I have to rewrite every block oone by one.</p>
  
  <p>I want to use a loop which generates the question blocks by creating the variables names using the array of the usernames.</p>
  
  <p>I tried the following (this is not the actual code, but throws the same error)</p>
  
  <pre><code>for (a=0; a &lt; 10; a++)
  {
   eval('var beginning'+a);
  }
  
  for (b=0;b&lt;10; b++)
  {
   eval('beginning' + b) = 1;
  }    
  </code></pre>
  
  <p>The first <code>for</code> loop runs fine, but when I try to assign any value it throws an error. (I use here two <code>for</code> loops for debugging only.)
  E.g.:</p>
  
  <pre><code> eval('beginning' + b) = 1;  //Throws: We're sorry, a server error occurred. Please wait a bit and try again.
   eval('beginning' + b + '= 1;');  //Throws: We're sorry, a server error occurred. Please wait a bit and try again.
   eval('beginning' + b = 1);  //Throws: Invalid assignment left hand side. (line 1, file "Code")
  </code></pre>
  
  <p>Using <code>eval</code> like this is also fine: <code>choices = eval('lCountries' + Names[i]).getChoices();</code>.</p>
  
  <p>How can I assign values to these variables in a <code>for</code> loop?</p>
  
  <p>Thank you very much in advance.</p>