# Array functions

This page describes the additional set of predefined Jsonnet functions for the [Data Transformer Script](https://docs.cloud.google.com/application-integration/docs/configure-data-transformer-script-task.md.txt) task available in Application Integration.

### Before you begin


To use the following predefined functions, you must import the `functions` library in your script. Importing the `functions` library lets you use both the standard Jsonnet functions and the predefined **Data Transformer** functions.


Application Integration supports Jsonnet functions library v0.20.0. For information about the Jsonnet standard functions, see [Jsonnet Standard Library](https://jsonnet.org/ref/stdlib.html).

*** ** * ** ***

### `Average`

| Syntax | ```html avg(arr) ``` |
| Description | Calculates the numerical average of all the values in an array. |
| Input parameter | **arr:** The input array. |
| Return type | `DOUBLE` |
| Output | Returns the average of all the values in the array. |
|---|---|

*** ** * ** ***

### `Contains`

| Syntax | ```html contains(arr, elem) ``` |
| Description | Checks the occurrence of the specified element in an array. |
| Input parameter | **arr:** The input array. **elem:** The array element to search. |
| Return type | `BOOLEAN` |
| Output | Returns **TRUE** if a match is found and **FALSE** otherwise. |
|---|---|

*** ** * ** ***

### `Max Array`

| Syntax | ```html maxArray(arr) ``` |
| Description | Finds the highest value in an array. |
| Input parameter | **arr:** The input array. |
| Return type | The data type of the input array. |
| Output | Returns the highest value found in the array. |
|---|---|

*** ** * ** ***

### `Min Array`

| Syntax | ```html minArray(arr) ``` |
| Description | Finds the lowest value in an array. |
| Input parameter | **arr:** The input array. |
| Return type | The data type of the input array. |
| Output | Returns the lowest value found in the array. |
|---|---|

*** ** * ** ***

### `Remove`

| Syntax | ```html remove(arr, elem) ``` |
| Description | Removes the specified element from an array. |
| Input parameter | **arr:** The input array. **elem:** The array element to remove. |
| Return type | The data type of the input array. |
| Output | Returns the updated array after removing the specified element. |
|---|---|

*** ** * ** ***

### `Remove At`

| Syntax | ```html removeAt(arr, index) ``` |
| Description | Removes an element from an array at the specified index. |
| Input parameter | **arr:** The input array. **index:** The array index of the element to remove. |
| Return type | The data type of the input array. |
| Output | Returns the updated array after removing the specified element. |
|---|---|

*** ** * ** ***

### `Sum`

| Syntax | ```html sum(arr) ``` |
| Description | Adds all the values in an array. |
| Input parameter | **arr:** The input array. |
| Return type | The data type of the input array. |
| Output | Returns the sum of all the elements in the array. |
|---|---|

*** ** * ** ***

### `GroupBy`

| Syntax | ```html groupBy(array, function) ``` |
| Description | Creates an object composed of keys generated from the results of running each element of array through the iteratee function. For example, `f.groupBy([1,1.3,1.8],std.floor)` would generate `{"1": [1,1.3,1.8]}`. |
| Input parameter | - **array:** The collection that the method iterates over. **function:** The function that is invoked for every element in the array. |
| Return type | `JSON` |
| Output | Returns the composed aggregate object. |
|---|---|

*** ** * ** ***

### `Zip`

| Syntax | ```html zip([arrays]) ``` |
| Description | It create an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second element of the given arrays, and so on. For example, `f.zip([[1, "one", "I"],[2, "two", "II"],[3, "three", "III"]])` would generate `[[1,2,3],["one", "two", "three"],["I", "II", "III"]]`. |
| Input parameter | **\[arrays\]:** This parameter holds the arrays to process. |
| Return type | `array` |
| Output | Returns the new array of regrouped elements. |
|---|---|

*** ** * ** ***

### `Unzip`

| Syntax | ```html unzip(array) ``` |
| Description | It creates an array of grouped elements. Accepts an array of grouped elements and also creates an array regrouping the elements to their pre-zip configuration. For example, `f.unzip([[1, "one", "I"],[2, "two", "II"],[3, "three", "III"]])` would generate `[[1,2,3],["one", "two", "three"],["I", "II", "III"]]`. |
| Input parameter | **array:** This parameter holds the array of grouped elements to process. |
| Return type | `array` |
| Output | Returns the new array of regrouped elements. |
|---|---|

## Recommendation

- Learn how to add and configure a [Data Transformer Script task](https://docs.cloud.google.com/application-integration/docs/configure-data-transformer-script-task.md.txt)