title: square bracket array access and handlebars template
body: <p>I'm working on a node project with handlebars tempting engine. I have a very large object I need to represent in a table. The user gets to pick which columns they want to see. </p>
  
  <p>I have a varable called columns that holds the user's selected columns, we'll pretend it looks like</p>
  
  <pre><code>columns = ['name','email']
  </code></pre>
  
  <p>and I have an array of large objects</p>
  
  <pre><code>items = [{
      name:'foo',
      email:'foo@foo.com',
      otherPropN:'other...'
  }, ...]
  </code></pre>
  
  <p>Here was my first attempt at rendering a table with only the columns name and email.</p>
  
  <pre><code>      &lt;table class="table"&gt;
                  &lt;thead&gt;
                      {{#each columns}}
                          &lt;th&gt;{{this}}&lt;/th&gt;
                      {{/each}}
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      {{#each items}}
                          {{#each ../columns}}
                              &lt;td&gt;{{*WHAT TO PUT HERE!*}}&lt;/td&gt;
                          {{/each}}
                      {{/each}}
                  &lt;/tbody&gt;
  
              &lt;/table&gt;
  </code></pre>
  
  <p>I need to get back into the scope of item so I can say <code>item[column]</code> But, I'm not sure how to do that.</p>
  
  <p>In EJS this is what I would do.</p>
  
  <pre><code>&lt;table class="table"&gt;
                  &lt;thead&gt;
                      &lt;% columns.forEach(function(column){ %&gt;
                          &lt;th&gt;&lt;%=column%&gt;&lt;/th&gt;
                      &lt;% }); %&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                                    &lt;% item.forEach(function(item){ 
                           columns.forEach(function(column){ %&gt;
                          &lt;td&gt;&lt;%=item[column]%&gt;&lt;/td&gt;
  
                          &lt;% });
                                     }); %&gt;
                  &lt;/tbody&gt;
  
              &lt;/table&gt;
  </code></pre>
  
  <p>Thanks!</p>