title: How can I get the index of an array in a Meteor template each loop?
body: <p>Say I have an object, someObject:</p>
  
  <pre><code>{
    foo: "apple",
    myArray: ["abc", "def"]
  }
  </code></pre>
  
  <p>And a template helper that looks like this (and works fine):</p>
  
  <pre><code>getArray: function(){
    var self = this;
    self.myArray = self.myArray || [];    
    return self.myArray;
  }
  </code></pre>
  
  <p>How should I construct the html to get the array index?</p>
  
  <p>I've tried:</p>
  
  <pre><code>&lt;template name="someObject"&gt; // takes someObject as data
    {{#each getArray}}
      &lt;div class="item" data-value="{{WHAT GOES HERE?}}"&gt;{{this}}&lt;/div&gt;
    {{/each}}
  &lt;/template&gt;
  </code></pre>
  
  <p>In which case <code>this</code> successfully returns <code>"abc"</code> and <code>"def"</code>. Which is good. But how can I get the index of the array to put into the attribute <code>data-value</code>?</p>
  
  <p>I've tried <code>this.index</code> directly but it's undefined. I also tried using a helper:</p>
  
  <pre><code>&lt;template name="someObject"&gt; // takes someObject as data
    {{#each getArray}}
      &lt;div class="item" data-value="{{getindex}}"&gt;{{this}}&lt;/div&gt;
    {{/each}}
  &lt;/template&gt;
  </code></pre>
  
  <p>but in this helper <code>getIndex</code> when I console.log out <code>this</code> I see:</p>
  
  <pre><code>String {0: "a", 1: "b", 2: "c", length: 3}
  String {0: "d", 1: "e", 2: "f", length: 3}
  </code></pre>
  
  <p>Is it possible to get the index?</p>