Handlebar Helper Function: Filter
Filters a list of objects based on a field, comparison operator, and target value. The function supports string, number, and date comparisons.
| Parameter | Type | Description |
|---|---|---|
list | array | Required. The list of objects to filter. |
fieldName | string | Required. The field to filter on. |
comparisonOperator | string | Required. The comparison operator. See Comparison Operators. |
targetValue | any | Required. The value to compare against. |
filterAs | string | Required. The type to filter as. Valid values: "string", "number", "date". |
The comparisonOperator parameter supports the operators listed in this table for numeric and date comparisons.
| Symbolic Operator | Verbose Operator |
|---|---|
> | GREATER_THAN |
< | LESS_THAN |
== | EQUALS |
!= | NOT_EQUALS |
>= | GREATER_THAN_EQUALS |
<= | LESS_THAN_EQUALS |
For string comparisons, the comparisonOperator parameter supports these operators:
CONTAINSIS_NULLIS_NOT_NULL
The function returns a new list containing only the objects that match the filter criteria. If no objects match, it returns an empty list. If a parameter is missing or invalid, the function throws an exception.
These examples show how to use the filter function to filter this example array.
This example filters the array to include only objects where the age field is greater than 25.
The function returns [{"name": "Jane Doe", "age": 42}, {"name": "Edna Example", "age": 64}].
This example filters the array to include only objects where the name field contains the string "Doe".
The function returns [{"name": "John Doe", "age": 25}, {"name": "Jane Doe", "age": 42}].