where
Filters an array to include only items that possess a specific property value.
This requires providing the property name and the corresponding value.
Parameters
array{Array}: The array to filter. This parameter is required. If the type is incorrect, an empty array is returned.key{String}: The property key to filter by. This parameter is required. If the type is incorrect, an empty array is returned.[value]{String}: The property value to filter by. This parameter is optional and defaults to a truthy evaluation.returns{Array}: The filtered array.
Usage
{{where array key [value]}}
Example
{{ assign 'filter_products' (where collection.products 'vendor' "Natural Threads") }}
Products from Natural Threads:
{{#each filter_products as |product| }}
- {{ product.title }}
{{/each}}
Filtering Boolean Properties with True Values
You can filter items that have a true boolean property value. This requires specifying only the property name.
{{ assign 'available_products' (where collection.products 'available') }}
Available products:
{{#each available_products as |product| }}
- {{ product.title }}
{{/each}}
Was this article helpful to you?