---
title: "where"

doc_type: static
doc_category: static
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/handlebars/helpers/array/where'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/handlebars/helpers/array/where.md'
---


# where

过滤数组以仅包含具有特定属性值的项目。

这需要您提供属性名称和关联值。

## 属性

- `array` `{Array}` 数组，必填, 如果类型不对，返回空数组。
- `key` `{String}` 属性 key，必填，如果类型不对，返回空数组。
- `[value]` `{String}` 属性 value, 可选，默认为 truthy 判断
- `returns` `{Array}` 数组

## 用法

```handlebars
{{where array key [value]}}
```

## 例子

<Example data={['collection.products.{vendor, title}']}>
  ```handlebars
  {{ assign 'filter_products' (where collection.products 'vendor' "Natural Threads") }}

  Products from Natural Threads:

  {{#each filter_products as |product| }}
    - {{ product.title }}
  {{/each}}
  ```
</Example>


### 过滤具有true值的布尔属性

您可以过滤具有`true`布尔属性值的项目。这要求您仅提供属性名称。

<Example data={['collection.products.{available, title}']}>
  ```handlebars
  {{ assign 'available_products' (where collection.products 'available') }}

  Available products:

  {{#each available_products as |product| }}
    - {{ product.title }}
  {{/each}}
  ```
</Example>
