%dw 2.0
import * from dw::core::Arrays
var users = ["Mariano", "Leandro", "Julian"]
output application/json
---
take(users, 2)
DataWeave
take
take<T>(array: Array<T>, n: Number): Array<T>
Selects the first n
elements. It returns an empty array when n <= 0
and the original array when n > sizeOf(array)
.
Introduced in DataWeave version 2.2.0.
Parameters
Name | Description |
---|---|
|
The array of elements. |
|
The number of elements to select. |
Example
This example outputs an array that contains the values of first two elements of the input array.
Source
Output
[
"Mariano",
"Leandro"
]
json
take(array: Null, n: Any): Null
Helper function that enables take
to work with a null
value.
Introduced in DataWeave version 2.4.0.