---
schema_version: "1"
id: b5110dd52365eb808c94f1e5dd17cfa793048858c045c403b02f8a8a344eda50
title: takeWhile
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-objects-functions-takewhile.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-objects-functions-takewhile
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 2ef29bd0fec47b834888609a6d3061ec331a7147577282146042b766e6c94edd
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# takeWhile

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

## takeWhile(Object, (value: Any, key: Key) -> Boolean): Object

Selects key-value pairs from the object while the condition is met.

_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><code>obj</code></p></td><td><p>The object to filter.</p></td></tr><tr><td><p><code>condition</code></p></td><td><p>The condition (or expression) used to match a key-value pairs in the object.</p></td></tr></tbody></table>

### Example

This example iterates over the key-value pairs in the object and selects the elements while the
condition is met. It outputs the result into an object.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Objects
output application/json
var obj = {
  "a": 1,
  "b": 2,
  "c": 5,
  "d": 1
}
---
obj takeWhile ((value, key) ->  value < 3)
```

#### Output

```json
{
  "a": 1,
  "b": 2
}
```
