• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

150
Views
In handlebars, how to know if I'm at the last occurence of the parent array

I'm struggling on a little problem of mine in a handlebars project. I am working with a set of nested arrays like so:

[
   [
      [
         {Object: "Object1"},
         {Object: "Object2"}
      ],
      [
         {Object: "Object3"},
         {Object: "Object4"}
      ]
   ],
   [
      [
         {Object: "Object5"},
         {Object: "Object6"}
      ],
      [
         {Object: "Object7"},
         {Object: "Object8"}
      ]
   ],
   [
      [
         {Object: "Object5"},
         {Object: "Object6"}
      ],
      [
         {Object: "Object7"},
         {Object: "Object8"}
      ]
   ]
]

I know i can use the @first and @last booleans to know if I'm at the last element of the currently iterating array.

{{#each foo}}
    <div class='{{#if @first}}first foo{{/if}}
                {{#if @last}} last foo{{/if}}'>
      {{@key}} - {{@index}}
    </div>
{{/each}}

but what if I want to know whether or not I'm on the last element of a parrent array?

{{#each fooParent}}
   {{#each foo}}
       <div class='{{#if @first}}first foo not fooparent{{/if}}
                   {{#if @last}} last foo not fooparent{{/if}}'> <!-- How can I know here 
                                                                      that I am on the 
                                                                      last item of the 
                                                                     fooParent array? --> 
         {{@key}} - {{@index}}
       </div>
   {{/each}}
{{/each}}

anyone know how to "get back" in the arrays to know, for example, if I'm on the last element of parent array?

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error