1. Home
  2. Tutorials
  3. Working with APIs
  4. Find the Max Value in an API Array

Find the Max Value in an API Array

max iterate

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:

  1. 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. create max vars
  2. 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 plus button to add an Action, selecting Iterate through Array.
    • In the input, select the array from your API response, via the Event Data container.
      select array max

    Save the Action.

  3. In the nested Item Event, add another Action, choosing Set Value.
    • In the first input, select the curr variable, and in the second select the array item field you want to find the max for, via the Event Data container. select max field
  4. After the Set Value Action, add another to the Item Event, choosing If… Else.
    • In the first input, select the curr variable. In the center, select the > operator to test if the current value is greater than the max. In the third, select the max variable. max test
  5. In the nested True Event, add a Set Value Action. Set the max variable to the value of the curr variable. max curr
  6. After the iterate Action (the last plus plus button in the window), add an Action to use your max value, for example Set Value to display it in an Element. use max

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.

Was this article helpful to you? Yes No

How can we help?