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.

ParameterTypeDescription
listarrayRequired. The list of objects to filter.
fieldNamestringRequired. The field to filter on.
comparisonOperatorstringRequired. The comparison operator. See Comparison Operators.
targetValueanyRequired. The value to compare against.
filterAsstringRequired. 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 OperatorVerbose Operator
>GREATER_THAN
<LESS_THAN
==EQUALS
!=NOT_EQUALS
>=GREATER_THAN_EQUALS
<=LESS_THAN_EQUALS

For string comparisons, the comparisonOperator parameter supports these operators:

  • CONTAINS
  • IS_NULL
  • IS_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}].