Open Navigation


Loop through a list of items or the properties of an object
On This Page


The 'Loop Collection' connector on Tray allows you to iterate over each element of a specified array or object.

Loops are all about repeating the same steps multiple times. If you want to send an email to a list of users then you would pick the first user, get their email address, send the email, then move on to the next user. Loops make this sort of operation possible.

In Tray we always loop over a collection. A collection is a group of items and looping over a collection means looking at each item in the collection one by one and then performing the same steps for each item.

There are two kinds of collections that you can loop over: Lists and Objects. Let's take a look at these in more detail.


In Tray we use the terms Array and List interchangeably. Both of them mean a collection of items which are in a fixed order. These items can be complex - for example you could have a list in which each item is all of the data about a particular user. Common things that you might do to a list include adding items to it, checking whether a particular item is contained within a list, or counting the number of items in a list.


Objects are similar to lists in that you can use them to store a collection of items. The difference with Objects is that each item has a unique key which can be used to retrieve an item when you need it. Also, when you loop over the items they could be in any order whereas with a List the items will always be in the same order.

The question about whether to use a list or an object really depends on whether you need to process all of the items every time (use a list) or if you ever need to only access one of the items (use an object).

Looping over a list works in almost exactly the same way as an object, only you do not have a key available on each iteration - only a value.

Was this article helpful?
On This Page