Contact Us 1-800-596-4880

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

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"
]

take(array: Null, n: Any): Null

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

Introduced in DataWeave version 2.4.0.