Array Functions
Letβs explore the array functions in Make.com. This guide will show you how to work with arrays, whether youβre slicing, merging, filtering, or sorting.
Table of Contents
Let’s do this! π
Introduction to array functions
Array functions in Make.com are all about working with lists of data.
They let you sort, filter, and tweak these lists to fit your needs.
For example, you can pull out specific items, combine different lists, or rearrange the data. These functions make it simple to automate tasks and manage your lists efficiently.
Below is what the mapping panel for working with arrays look like;
The emptyarray
variable, as the name suggests, creates an empty array.
All the functions I’ll explain in a bit.
What is an array?
First things first, maybe you’ve never heard of arrays before, which I totally get because before I got started with Make.com I also never heard of them π
The basics of an array
It’s actually not too difficult, it’s basically just a list of things of the same type.
(in techy terms, it’s a data structure that holds a collection of items in a single variable)
For example, an array of numbers might look like [1, 2, 3, 4, 5]
, while an array of names could be ["Alice", "Bob", "Charlie"]
.
And each of those items in the list, the array, we can access by its position, the index. The first item in the list is 0, the second item is 1, the third item is 2, and so on.
So if we would wanna get the third name out of ["Alice", "Bob", "Charlie"]
, we would use index 2.
Alice
=0
Bob
=1
Charlie
=2
How arrays are structured
Earlier I showed you the examples [1, 2, 3, 4, 5]
and ["Alice", "Bob", "Charlie"]
.
But what are those brackets, commas, and double quotes for? π€
Well, it’s a way to make our list (the array).
[ ]
indicates it is a list.,
separates the list items.""
double quotes means it’s a text. That’s why the numbers don’t have double quotes.
Arrays your scenarios
In your scenarios in Make.com, you recognize arrays like this:
See? They already visualized the list for you, and don’t show you the brackets/commas/quotes π
They even made the numbering a bit easier to understand, where the first item in the array has a 1
in front of it instead of a 0
.
All array functions explained
Let’s dive into how each function works, with examples that will help you master them in no time! π€
add
The add()
function adds new values to an array and returns the updated array.
add([“apple”, “banana”];“cherry”)
= [“apple”, “banana”, “cherry”]
contains
Checks if an array contains a specific value, returning true
if found and false
otherwise.
contains([“apple”, “banana”, “cherry”];“banana”)
= true
deduplicate
Removes duplicate values from an array, leaving only unique items.
deduplicate([“apple”, “banana”, “banana”, “cherry”])
= [“apple”, “banana”, “cherry”]
distinct
Similar to deduplicate()
, but it can also check a specific key in complex objects to remove duplicates.
distinct(Contacts[];name)
= Removes duplicate contacts based on the name
property
first
Returns the first element of an array.
first([“apple”, “banana”, “cherry”])
= “apple”
This is similar to using the get()
function.
get([“apple”, “banana”, “cherry”];1)
= “apple”
flatten
Flattens nested arrays into a single array. Specify a depth if you don’t want it fully flattened.
flatten([[1, 2],[3, 4],[5, 6]])
= [1, 2, 3, 4, 5, 6]
join
Combines all items in an array into a string, with an optional separator.
join([“apple”, “banana”, “cherry”];“, “)
= “apple, banana, cherry”
keys
The keys()
function returns an array of the keys (or properties) of an object or array.
keys({“name”: “John”, “age”: 30})
= [“name”, “age”]
last
Returns the last element of an array.
last([“apple”,”banana”,”cherry”])
= “cherry”
length
Returns the number of elements in an array.
length([“apple”,”banana”,”cherry”])
= 3
map
Transforms a complex array by extracting specific values based on a key, and optionally filters them.
map(Emails[];email)
= [“[email protected]”, “[email protected]”]
merge
Merges two or more arrays into one.
merge([“apple”, “banana”];[“cherry”, “date”])
= [“apple”, “banana”, “cherry”, “date”]
remove
Removes specified values from an array of primitive values (text or numbers).
remove([“apple”, “banana”, “cherry”];“banana”)
= [“apple”, “cherry”]
reverse
Reverses the order of the elements in an array.
reverse([“apple”, “banana”, “cherry”])
= [“cherry”, “banana”, “apple”]
shuffle
Randomly reorders the elements in an array.
shuffle([“apple”, “banana”, “cherry”])
= [“cherry”, “apple”, “banana”]
slice
Returns a new array with selected items, starting at the start
index and optionally ending before the end
index.
slice([“apple”, “banana”, “cherry”, “date”];1;3)
= [“banana”, “cherry”]
sort
Sorts the elements of an array based on the specified order
(ascending or descending) and optional key
for complex objects.
sort([“banana”, “apple”, “cherry”];asc)
= [“apple”, “banana”, “cherry”]
toArray
Converts a collection into an array of key-value pairs.
toArray(collection)
= [{“key1”: “value1”}, {“key2”: “value2”}]
toCollection
Converts an array of objects into a collection by specifying a key and value.
toCollection([{“name”: “John”, “age”: 30}];name;age)
= { “John”: 30 }