Getting the Size of a Collection/Array?

Probably a really simple one, but I am looping through a collection of items (provided in a in a KM Custom form). For the last item I need to handle it slightly differently. So, what is the best way to work out if it's the last item?

FWIW, I am using a counter as I loop through, so I could do 'If itemCount == collection size (pseudocode)'

Thanks

"a collection of items (provided in a in a KM Custom form)"

What do you mean by KM Custom form ? Is it using Prompt Input Action or Custom HTML Prompt action ? How is the collection of items defined in the form ?

Yes, it's a Custom HTML Prompt.

In that form is a in which I enter multiple lines.

If I type:

One
Two
Three

It saves that in a variable with a name that matches the 's name, which is simply "Items" (super generic as I use a standard form that is used to collect stuff in this way for many different purposes).

I then loop through whatever is in this"Items" variable. So in this example, I want to know when I have got to the last line in that collection as I then need to do something different.

So, how can I know that it's the last item in that collection?

You can use the Line Count filter action to get the number of lines for your "If itemCount = collection size" check:

That did the job! Now I have to investigate what other things filter can do :slight_smile:

1 Like