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
-
uniquepreserves 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.
-
uniquereturns a new array and does not modify the original. - Wrap
uniquein a#eachblock to iterate over the deduplicated results, or combine it withjointo produce a delimited string.