---
schema_version: "1"
id: 5326921d3735b0d195e7c84b2238871190385dc2f9c750164d3e63beeea706a7
title: takeWhile
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-objects-functions-takewhile.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-objects-functions-takewhile
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 66111f9bc08be59384f9f78b55073265a0bb133c4e44dc0b67bd6fa3b7bac0b9
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# takeWhile

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

## takeWhile<T>(obj: Object, condition: (value: Any, key: Key) -> Boolean): Object

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

_Introduced in DataWeave version 2.3.0._

### 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
}
```
