---
schema_version: "1"
id: 2f13526bd759c22a9337f668ee113a67b21f59c762af810aa1bdf406a92d50c6
title: firstWith
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-arrays-functions-firstwith.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-arrays-functions-firstwith
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 7b7726048062b5e87faa5e67e48c29e63c71cbcbba1dba04f96c4f49a090438d
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# firstWith

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## firstWith(Array<T>, (item: T, index: Number) -> Boolean): T | Null

Returns the first element that satisfies the condition, or returns `null` if no element meets the
condition.

_Introduced in DataWeave 2.3.0. Supported by Mule 4.3 and later._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p>array</p></td><td><p>The array of elements to search.</p></td></tr><tr><td><p>condition</p></td><td><p>The condition to satisfy.</p></td></tr></tbody></table>

### Example

This example shows how `firstWith` behaves when an element matches and when an element does not
match.

#### Source

```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")
}
```

#### Output

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