---
schema_version: "1"
id: b372233806dcf2d276e4dbaaf816a1ed1e1efdd97d40402d75fc5a79a8bdba8d
title: firstWith
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.4/dw-arrays-functions-firstwith.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.4/dw-arrays-functions-firstwith
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4df74ea894cf5bb2b5446b2416a1322128d1770b8c29d535758af5e07439e434
description: MuleSoft Documentation Site
release: "2.4"
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 で導入されました。_​