Issue with Accessing Last Element in an Array within a Filter

Hi everyone,

I am encountering an issue when trying to access the last element of an array within a filter in Make.com.

Context:

  • I am working with an array from an HTTP request, and I want to apply a filter condition on the last element of this array.
  • When using length() and -1 to access the last element of the array in a variable, it works perfectly (e.g., 5. Data.data[length(5. Data.data[]) - 1].o).
  • However, when I try to use the same expression in the filter, the filter always defaults to the first array element instead of the last one.

I want to apply the filter directly on the last element of the array without using additional workarounds like storing the result in a variable first, as I want to minimize operations in my scenario.

Thanks in advance for any insights!

image

Added Blueprint

blueprint (1).json (32.9 KB)

Hi @Sam_Krausz

You can use last() function to get the last element of an array.
image

Best regards,

Msquare Automation
Gold Partner of Make
@Msquare_Automation

Hello @Sam_Krausz,
As suggested by @Msquare_Automation use the last() function which returns the last element of the given array. https://www.make.com/en/help/functions/array-functions#last--array-

Then use get() to get the specific key from the collection/array. https://www.make.com/en/help/functions/general-functions#get--object-or-array--path-

This is not the same, but the example function syntax will look like this.
get(last(array);key)

:+1:

Thanks for all your help - I apologize for not being clear in my previous post.

I need to get the array that is one before the last array.

Sometimes I have 170 arrays and one time I may have only 101 or so, but I need to get the array that is one before the last one regardless of the number of arrays.

Hi Sam

You can do it like this. Make sure the Data in my spot is your Data array.

Wow, Thanks

What is the get function doing?

1 Like
  • length(168.Data) - 1: This calculates the index of the second-to-last item (because length() gives the last index, and subtracting one more moves it back to the second-to-last position).
  • get(168.Data; length(168.Data) - 1): The get() function then retrieves the item at this calculated index, which is the second-to-last element in the Data array.
    So we get the second to last element in the Array

Also please mark the above as the solution. To keep the community clean and if others need help with the same problem they can find it easily. thanks :slight_smile:

3 Likes