Loop
Iterates over a collection and runs children for each item.
When to use?
When you want to iterate over each item in an array and do something with it.
How to use:
- You can name the element in the Name field
- Make sure you've got an indexed array by the way of Http Client, Json Reader or Set Parameter element
- In the Items field enter the name of the array, as shown in this example: ${array_name}
- In the Data collection item name enter the name under which you'll be able to access individual array items, for example: item
- You can skip iterations of as many items as you wish, starting from the beginning of the array, by entering an offset number in the Offset field
- Entering a limit number in the Limit field limits the loop to the specified number of iterations
- You can place any number of other elements inside the Loop element
- To access array values, use this syntax: ${item.value}
- To access array indexes, use this syntax: ${item.index}
- If you want to output array indexes, counting from number one instead of zero, use this: ${item.natural}
- To identify the first, or the last iteration, use this syntax: ${item.first}, {item.last}
Example of usage in case of a two dimensional array:
We created a two-dimensional array in this format: players[index]["score"], and we want to output player scores.
- Items: ${players}
- Data collection item name: player
- Next, we place a Text Response element inside the Loop element
- For output, in the Text Response element's TEXT field, we enter this: ${player.value.score}