Articles in this section

unique helper

The unique helper returns a new array with all duplicate values removed, preserving the order of first occurrences. Use it before iterating or combining results to ensure only distinct values are processed.

Syntax

{{unique array}}

array -- The array to deduplicate. Required. Works with arrays of primitive values: strings, numbers, and booleans.

Examples

Remove duplicates and join with commas

{{#each (unique record.tags)}}{{this}}{{#unless @last}},{{/unless}}{{/each}}

Input:

{ "record": { "tags": ["a", "a", "c", "b", "e", "e"] } }

Output: a,c,b,e

unique removes the duplicate "a" and "e", then #unless @last adds a comma after every element except the last.

Iterate over distinct values

{{#each (unique record.categories)}}
  {{this}}
{{/each}}

Input:

{ "record": { "categories": ["A", "B", "A", "C", "B"] } }

Output:

A
B
C

Duplicates "A" and "B" are removed and the first-occurrence order is preserved.

Usage notes

  • unique preserves the original order of first occurrences -- it doesn't sort the array.
  • Works only with arrays of primitive values (strings, numbers, booleans). Arrays of objects are not supported.
  • unique returns a new array and does not modify the original.
  • Wrap unique in a #each block to iterate over the deduplicated results, or combine it with join to produce a delimited string.