Contact Free trial Login

dropWhile

dropWhile(Array<T>, (item: T) -> Boolean): Array<T>

Drops elements from the array while the condition is met but stops the selection process when it reaches an element that fails to satisfy the condition.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters

Name Description

array

The array of elements.

condition

The condition (or expression) used to match an element in the array.

Example

This example returns an array that omits elements that are less than or equal to 2. The last two elements (2 and 1) are included in the output array because the function stops dropping elements when it reaches the 3, which is greater than 2.

Source

%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,3,2,1]
---
arr dropWhile $ < 3

Output

[
  3,
  2,
  1
]

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub