Skip to main content
Array helpers provide operations for working with lists and collections.

first

Returns the first element of an array.
{{first items}}
Example:
{{! items = ["Apple", "Banana", "Cherry"] }}
{{first items}}
Output: Apple
<p>Featured: {{first featuredProducts}}</p>

last

Returns the last element of an array.
{{last items}}
Example:
{{! items = ["Apple", "Banana", "Cherry"] }}
{{last items}}
Output: Cherry
<p>Most recent order: #{{last orderNumbers}}</p>

at

Returns the element at a specific index (zero-based).
{{at items 1}}
ArgumentTypeDefaultDescription
arrayarrayrequiredSource array
indexnumber0Index to retrieve
Example:
{{! items = ["Apple", "Banana", "Cherry"] }}
{{at items 1}}
Output: Banana

join

Joins array elements into a string with a separator.
{{join items ", "}}
ArgumentTypeDefaultDescription
arrayarrayrequiredArray to join
separatorstring”, “Separator between elements
Examples:
{{! tags = ["javascript", "nodejs", "api"] }}
{{join tags ", "}}
Output: javascript, nodejs, api
{{join tags " | "}}
Output: javascript | nodejs | api
<p>Categories: {{join categories ", "}}</p>
<p>Phone: {{join phoneParts "-"}}</p>

length

Returns the length of an array, string, or object.
{{length items}}
Examples:
{{! items = ["A", "B", "C"] }}
{{length items}}
Output: 3
<p>{{length items}} items in cart</p>
<p>{{length description}} characters</p>

contains

Returns true if the array contains a value.
{{contains array value}}
Example:
{{! roles = ["admin", "editor"] }}
{{#if (contains roles "admin")}}
  <span class="admin-badge">Admin</span>
{{/if}}

sum

Calculates the sum of array values or a specific property.
{{sum numbers}}
{{sum items "price"}}
ArgumentTypeDefaultDescription
arrayarrayrequiredArray to sum
propertystringnullProperty name to sum (for object arrays)
Examples:
{{! numbers = [10, 20, 30] }}
{{sum numbers}}
Output: 60
{{! items = [{price: 10}, {price: 20}, {price: 30}] }}
{{sum items "price"}}
Output: 60
<p>Total: {{currency (sum items "price") "USD"}}</p>
<p>Total Quantity: {{sum items "quantity"}}</p>

average

Calculates the average of array values or a specific property.
{{average numbers}}
{{average items "rating"}}
ArgumentTypeDefaultDescription
arrayarrayrequiredArray to average
propertystringnullProperty name (for object arrays)
Examples:
{{! scores = [85, 90, 78, 92] }}
{{average scores}}
Output: 86.25
<p>Average Rating: {{round (average reviews "rating") 1}} / 5</p>

max

Returns the maximum value in an array.
{{max numbers}}
{{max items "price"}}
ArgumentTypeDefaultDescription
arrayarrayrequiredArray to search
propertystringnullProperty name (for object arrays)
Examples:
{{! prices = [29.99, 49.99, 19.99] }}
{{max prices}}
Output: 49.99
<p>Highest Price: {{currency (max products "price") "USD"}}</p>

min

Returns the minimum value in an array.
{{min numbers}}
{{min items "price"}}
ArgumentTypeDefaultDescription
arrayarrayrequiredArray to search
propertystringnullProperty name (for object arrays)
Examples:
{{! prices = [29.99, 49.99, 19.99] }}
{{min prices}}
Output: 19.99
<p>Starting at {{currency (min products "price") "USD"}}</p>

Practical Examples

Order Summary

<div class="order-summary">
  <h3>Order Summary</h3>
  <p>Items: {{length items}}</p>
  <p>Total Quantity: {{sum items "quantity"}}</p>
  <p>Subtotal: {{currency (sum items "total") "USD"}}</p>
</div>

Tag List

<div class="tags">
  {{#if (isNotEmpty tags)}}
    <p>Tags: {{join tags ", "}}</p>
  {{else}}
    <p class="no-tags">No tags</p>
  {{/if}}
</div>

Price Range

<div class="price-range">
  <p>
    {{currency (min variants "price") "USD"}} - 
    {{currency (max variants "price") "USD"}}
  </p>
</div>

Statistics

<div class="statistics">
  <p>Total Sales: {{currency (sum orders "total") "USD"}}</p>
  <p>Average Order: {{currency (average orders "total") "USD"}}</p>
  <p>Largest Order: {{currency (max orders "total") "USD"}}</p>
  <p>Smallest Order: {{currency (min orders "total") "USD"}}</p>
</div>

Invoice Totals

<table>
  <tbody>
    {{#each lineItems}}
    <tr>
      <td>{{this.description}}</td>
      <td>{{this.quantity}}</td>
      <td>{{currency this.unitPrice "USD"}}</td>
      <td>{{currency (multiply this.quantity this.unitPrice) "USD"}}</td>
    </tr>
    {{/each}}
  </tbody>
  <tfoot>
    <tr>
      <td colspan="3">Total Items</td>
      <td>{{sum lineItems "quantity"}}</td>
    </tr>
    <tr>
      <td colspan="3">Subtotal</td>
      <td>{{currency (sum lineItems "total") "USD"}}</td>
    </tr>
  </tfoot>
</table>

Author List

<p>
  {{#if (eq (length authors) 1)}}
    Author: {{first authors}}
  {{else if (eq (length authors) 2)}}
    Authors: {{at authors 0}} and {{at authors 1}}
  {{else}}
    Authors: {{at authors 0}}, {{at authors 1}}, and {{subtract (length authors) 2}} others
  {{/if}}
</p>