If you have an array of data returned from an API response and you want to check for particular values in it, you can do so using the Iterate through Array Action. With an API request returning the array (which will be listed in Dropsource as a Data Source) added to a page in your app:
- Open the request Events and open the Event the array will be sent with (typically this will be
200: OK). Click the plus button to add an Action, selecting Iterate through Array.
Save the Action.
- In the nested Item Event, add another Action, this time choosing If… Else.
- In the first input, select the value from the array that you want to test, via the Event Data container.
- In the center input, select a comparison operator, for example == to test for equality with your next input.
- In the last input, select a value to compare the array field against – this must match the type of the field.
- In the nested True and/or False Events, add whatever processing you want to execute when your test returns true or false for the array value. For example, you can update an Element in the page using the Set Value Action to indicate that a condition has been met.
You can display an array of map locations from an API using the iterate Action. If you want to display images from an array in an API response, you can do so using Element loaded Events. You can also use a conditional Action in conjunction with array iteration to filter results or to compare them. If you want to check a value from a response field that isn’t in an array, you can also use status code Events. You can alternatively carry out processing on the first n items in an array returned from an API.