title: Javascript strange behavior with for loop and ejs variable
body: <p>I am currently stuck regarding this code for about 3 hours now. I'm sure I am making a very silly mistake and hopefully somebody can help me point this out. </p>
  
  <p>Basicially I cannot do this </p>
  
  <pre><code>var id = '&lt;%=data[i]._userDetail._id%&gt;'; 
  </code></pre>
  
  <p>But I can do this </p>
  
  <pre><code>var id = '&lt;%=data[1]._userDetail._id%&gt;'; 
  </code></pre>
  
  <p>Why can't I use "i" as variable here? I have tested this and it is not an out of bound issue. Every time I use "i" it will tell me that the variable is undefined "_userDetail" etc.</p>
  
  <pre><code>&lt;script&gt;
  
          for (var i = 0; i &lt; '&lt;%=data.length%&gt;'; i++) {
              if(document.getElementById("select_user").options[i].value === '&lt;%=requestUserID%&gt;' ){
  
                  document.getElementById("select_user").selectedIndex = i;
              }
  
              var id = '&lt;%=data[1]._userDetail._id%&gt;';
              var nickname = '&lt;%=data[1].nickname%&gt;';
              var phone = '&lt;%=data[1].phone%&gt;';
              var lineID = '&lt;%=data[1].lineID%&gt;';
  
  
                  document.getElementById("requestUserID").value = id;
                  document.getElementById("nickname").value = nickname;
                  document.getElementById("phone").value = phone;
                  document.getElementById("lineID").value = lineID;
  
  
          }
      &lt;/script&gt;
  </code></pre>