---
schema_version: "1"
id: 414afd664e42714630f18ced4f64b0db2f5d68511379c129e5f320b79dbd5cd3
title: firstWith
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.5/dw-arrays-functions-firstwith.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.5/dw-arrays-functions-firstwith
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ead35b77855a6366085d7e50295a557fb4b2fb5e711d42ad17a9ea4e155bab8c
description: MuleSoft Documentation Site
release: "2.5"
latest: false
---
# firstWith

## [](#firstwith1)firstWith<T>(array: Array<T>, condition: (item: T, index: Number) -> Boolean): T | Null

条件を満たす最初の要素を返すか、条件を満たす要素がない場合は ​`null`​ を返します。

_DataWeave バージョン 2.3.0 で導入されました。_

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>array</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">検索する要素の配列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>condition</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">満たす条件。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、要素が一致する場合と要素が一致しない場合の ​`firstWith`​ の動作を示します。

#### [](#ソース)ソース

```DataWeave
%dw 2.0
output application/json
import firstWith from dw::core::Arrays
var users = [{name: "Mariano", lastName: "Achaval"}, {name: "Ana", lastName: "Felisatti"}, {name: "Mariano", lastName: "de Sousa"}]
---
{
  a: users firstWith ((user, index) -> user.name == "Mariano"),
  b: users firstWith ((user, index) -> user.name == "Peter")
}
```

#### [](#出力)出力

```Json
{
  "a": {
    "name": "Mariano",
    "lastName": "Achaval"
  },
  "b": null
}
```

## [](#firstwith2)firstWith(array: Null, condition: (item: Nothing, index: Nothing) -> Any): Null

`firstWith`​ を ​`null`​ 値に使用できるようにするヘルパー関数。

_DataWeave バージョン 2.4.0 で導入されました。_