If you have an array of data returned from an API response and you need to find the maximum (or minimum) value in it, you can do so by adding Actions to the request Events. With an API request returning an array added to a page in your app:
- Create two Page Variables on the right of the editor. Give them the names “max” and “curr”, and the same number type as the field you’ll be finding the max value for in your API response.
- Open the API tab and select the request. Open Events and select the relevant status code (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, choosing Set Value.
- After the Set Value Action, add another to the Item Event, choosing If… Else.
- In the nested True Event, add a Set Value Action. Set the max variable to the value of the curr variable.
- After the iterate Action (the last plus button in the window), add an Action to use your max value, for example Set Value to display it in an Element.
You can also filter API array results before displaying data in your app. If you simply need to find a particular value in an array you can also use the iterate and conditional Actions. For more on location and mapping Actions, see the native functionality tutorials.