Articles in this section

last helper

This data variable returns true for the last element of an array or an object. When iterating through values in an array, the output always starts with 0. In a nested loop, refer to the immediate parent with the index @../last, and so on.

Template

Context

Output

{{#each @root.child}}
{{#if @last}}
{{@key}}
{{/if}}
{{/each}}
{
  "title": "My New Post",
  "body": "This is my first post!",
  "array": [1,2,3,4],
  "message": "This is the message.",
  "child": {
    "childTitle": "Child Title",
    "childBody": "Child Body"
  }
}
childBody
{{#each array}}
{{#if @last}}
{{@key}}
{{/if}}
{{/each}}
{
  "title": "My New Post",
  "body": "This is my first post!",
  "array": [1,2,3,4],
  "message": "This is the message.",
  "child": {
    "childTitle": "Child Title",
    "childBody": "Child Body"
  }
}
3
{{#each array}}
{{#if @last}}
{{@key}}
{{/if}}
{{/each}}
{
  "title": "My New Post",
  "body": "This is my first post!",
  "array": [
    "apple",
    "orange",
    "pear",
    "banana"
  ],
  "message": "This is the message.",
  "child": {
    "childTitle": "Child Title",
    "childBody": "Child Body"
  }
}
3