---
title: Array functions
slug: array-functions
description: Sort, filter, and transform arrays to manipulate complex data structures
image: https://archbee-image-uploads.s3.amazonaws.com/oAyFj2GHlBeBVWF5OAir2/JtyYV2Ruf5cul2YLg1uLU_domino-zoomin-purple-a-1.png
docTags: 
createdAt: 2025-02-03T13:29:15.598Z
---

You can use array functions to transform [array data](docId\:WohDzDDIOV0Ly51gr9Dgy). Array functions can, for example, search and sort the items in an array, perform mathematical operations, convert arrays to collections, reorder the items in an array, and more. Below is a list of supported array functions and a description what of each function does.

## add

**add (array; value1; value2; ...)**

Adds values specified in parameters to an array and returns that array.

## arrayDiff

**arrayDiff(array1; array2)**

Compares two arrays and returns items that are in the first array but not in the second.

```none
arrayDiff(1, 2, 3, 4; 3, 4, 5, 6)
1, 2
```

```none
arrayDiff(arrayDiff("a", "b", "c"; "b", "d")
"a", "c"
```

## arrayIntersect

**arrayIntersect(array1; array2)**

Compares two arrays and returns only the items found in both.

```none
arrayIntersect(1, 2, 3, 4; 3, 4, 5, 6)
3, 4
```

```none
arrayIntersect("a", "b", "c"; "b", "c", "d")
"b", "c"
```

## contains

**contains (array; value)**

Verifies if an array contains the value.

## deduplicate

**deduplicate (array)**

Removes duplicates from an array.

## distinct

**distinct (array; \[key])**

Removes duplicates inside an array. Use the *key* argument to access properties inside complex objects. To access nested properties, use dot notation. The first item in an array is index 1.

```none
distinct( Contacts[] ; name )
Removes duplicates inside an array of contacts by comparing the name property.
```

## first

**first (array)**

Returns the first element of an array.

## flatten

**flatten (array)**

Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

More details about this function can be found in the [Array.prototype.flat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) documentation.

## join

**join (array; separator)**

Concatenates all the items of an array into a string, using a specified separator between each item.

## keys

**keys (object)**

Returns an array of a given object's or array's properties.

## last

**last (array)**

Returns the last element of an array.

## length

**length (array)**

Returns the number of items in an array.

## map

**map (complex array; key;\[key for filtering];\[possible values for filtering separated by a comma])**

Returns a primitive array containing values of a complex array. Allows filtering values. Use raw variable names for keys.

```none
map( Emails[] ; email )
Returns a primitive array with emails.
```

```none
map( Emails[] ; email ; label ; work,home )
Returns a primitive array with emails that have a label equal to work or home.
```

::embed[See also [Mapping: Accessing array's elements by a key](docId:WohDzDDIOV0Ly51gr9Dgy) and our [Extract an item and/or its value from an array of collections](https://www.youtube.com/watch?v=W9CgDTeppmE) video tutorial.]{url="https://www.youtube.com/watch?v=W9CgDTeppmE"}

## merge

**merge (array1; array2; ...)**

Merges two or more arrays into one array.

## remove

**remove (array; value1; value2; ...)**

Removes values specified in the parameters of an array. Effective only in case of primitive arrays of text or numbers.

## reverse

**reverse (array)**

The first element of the array becomes the last element and vice versa.

## shuffle

**shuffle (array)**

Shuffles (randomly reorders) elements of an array.

## slice

**slice (array; start; \[end])**

Returns a new array containing only selected items. The first item in the array has an index of 0.

## sort

**sort (array; \[order]; \[key])**

Sorts values of an array. The valid values of the `order` parameter are:

- `asc` (default) - ascending order: 1, 2, 3, ... for type Number. A, B, C, a, b, c, ... for type Text.
- `desc` - descending order: ..., 3, 2, 1 for type Number. ..., c, b, a, C, B, A for type Text.
- `asc ci` - case insensitive ascending order: A, a, B, b, C, c, ... for type Text.
- `desc ci` - case insensitive descending order: ..., C, c, B, b, A, a for type Text.

Use the `key` parameter to access properties inside complex objects. Use raw variable names for keys. To access nested properties, use dot notation. The first item in an array is index 1.

```none
sort( Contacts[] ; name )
Sorts an array of contacts by the name property in default ascending order.
```

```none
sort( Contacts[] ; desc ; name )
Sorts an array of contacts by the name property in descending order.
```

```none
sort( Contacts[] ; asc ci ; name )
Sorts an array of contacts by the name property in case insensitive ascending order.
```

```none
sort( Emails[] ; sender.name )
Sorts an array of emails by the sender.name property.
```

## toArray

**toArray (collection)**

Converts a collection into an array of key-value collections.

## toCollection

**toCollection (array; key; value)**

Converts an array containing objects with key-value pairs into a collection.
