In this tutorial we're going to learn about using the loop connector to iterate through your data.
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).
The Loop Collection Connector
The Loop Collection connector is used to loop over a collection. In this video we'll take a look at how the Loop Collection connector works and what output you can expect from it.
Looping over a list works in almost exactly the same way as an object, you simply do not have a key available on each iteration - only a value.