Contact Us 1-800-596-4880

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

array

The array of elements.

n

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

 %dw 2.0
 import * from dw::core::Arrays
 var users = ["Mariano", "Leandro", "Julian"]
 output application/json
 ---
 take(users, 2)

Output

[
  "Mariano",
  "Leandro"
]