E M
E M

Reputation: 41

How to get index last position in Handlebars each helper?

I know that this's the way to display the index of an array inside the 'each' helper:

{{#each array}}
  {{@index}} 
{{/each}}

My question is how to display the array length instead. Something like:

    {{#each array}}
      {{array.length}} 
    {{/each}}

By the way, the above code doesn't work. I put many things there, but nothing worked out yet.

Upvotes: 0

Views: 83

Answers (1)

Matt Coy
Matt Coy

Reputation: 1091

You can just use @last

{{#each array}}
  {{#if @last}} this is the last item {{/if}}
{{/each}}

https://handlebarsjs.com/guide/builtin-helpers.html#each

Upvotes: 0

Related Questions