%dw 2.0
import * from dw::core::Arrays
var users = ["Mariano", "Leandro", "Julian"]
output application/json
---
take(users, 2)
DataWeave
take
take(Array<T>, 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 2.2.0. Supported by Mule 4.2 and later.
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