Contact Us 1-800-596-4880

dropWhile

dropWhile<T>(array: Array<T>, condition: (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 version 2.2.0.

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
]

dropWhile(array: Null, condition: (item: Nothing) -> Any): Null

Helper function that enables dropWhile to work with a null value.

Introduced in DataWeave version 2.4.0.