title: How to create custom for loop in handlebars template
body: <p>I am new to <code>NodeJS</code> and <code>ExpressJS</code>. I want to create custom <code>for</code> loop for traversing through the from the <code>NodeJS</code> data via <code>index</code> like we are using for not <code>for</code> loop.</p>
  
  <p>Check below code from <code>NodeJS</code> where I am getting all users of role <code>User</code> and passing users to <code>handlebars</code> view.</p>
  
  <pre><code>exports.getAll = function (req, res) {
      models.Users.findAll({
          where: {
              role: {$ne: "User"}
          }
      }).then(users =&gt; {
          return res.render('users/index', {users: users});
      }).catch(error =&gt; {
          return res.json(error);
      });
  };
  </code></pre>
  
  <p>Checkout my handlebars view. From below code I am able to traverse through all the users, but I don't want to use like that. </p>
  
  <p>I want to use like we are using normal <code>for</code> loop <code>for(index = 0; index &lt; count(users); index++</code></p>
  
  <pre><code>&lt;table class="table table-hover table-light"&gt;
      &lt;thead&gt;
          &lt;tr class="uppercase"&gt;
              &lt;th class="col-md-2"&gt; Login &lt;/th&gt;
              &lt;th class="col-md-6"&gt; Description &lt;/th&gt;
              &lt;th class="col-md-2"&gt;  &lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          {{#each users}}
          &lt;tr&gt;
              &lt;td&gt; {{username}} &lt;/td&gt;
              &lt;td&gt; {{about_me}} &lt;/td&gt;
              &lt;td&gt;
                  &lt;button type="button" id="#basic" data-toggle="modal" href="#basic" class="btn btn-blue btn-xs"&gt;Edit&lt;/button&gt;
                  &lt;button type="button" class="btn btn-danger btn-xs"&gt;Remove&lt;/button&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          {{/each}}
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I tried creating helper function. Check below code</p>
  
  <pre><code>hbs.registerHelper('for', function(from, to, incr, block) {
      var accum = '';
      for(var i = from; i &lt; to; i += incr)
          accum += block.fn(i);
      return accum;
  });
  </code></pre>
  
  <p>Is it possible to create normal <code>for</code> loop in <code>handlebars</code> template engine?</p>
  
  <p>Can anyone help me to create new helper function?</p>