Cognito Forms: Selecting Individual Items From an Array

I have created an array, using the .Split() functionality, I would like to now reference each item (it I believe) in that array, specifically.

How do I achieve that?

The rest of this you don't need to read, but I'll try to provide more information.

I am now going to use an example of something that I might like to do, this is not literally all I want to do.

So. Let's say a user has input the following data in to the 'Inputta' field:


Now, in the 'Arraya' field, I have:


Let's say I would like to select the "ddd" entry in that array, how would I do that?

I've tried using the .Where() functionality, eg: ".Where(ItemNumber = 4)", but even if that did work (it doesn't), it would be no use for if I need to be iterative.

I've tried to play with the .Select() functionality, but that's not helpful, either, as I can't find decent information on how it even works.

So, on to that iterative tip, to build on this example, I have a secondary requirement of the form, which is to pick an item from the array from an incremented integer.

We'll imagine I know how to increment an integer, and have that information already, either in a separately generated .Split() field, or as an integer calculation in a Repeating Section.

How would I use the integer to find the array entry in the 'Arraya' field?

Basically, how would I select item 1 (from the second array), then item 2, etc?

This isn't a separate question, I'm just explaining further the requirement.

As an addendum, I'd love to know how to create an array of incremental integers leading to a pre-determined max number. ;-)

For the record, I have StartPaged this thoroughly.

  1. I can't find a full reference chart for the functions available anywhere online.
  2. The list on CF only lists a subset of the available functions (for example, the .Select() array functionality is not listed)
  3. Everywhere else appears to handle other specific functions.

None of that is stated to cast any disdain anywhere, purely to indicate that I have looked, perhaps my StartPage Fu is just not that strong. Either way, apologies for asking here.

Answers 2

  • So, @MarkShamy is right, however it will only work for a 0 value.

    In order to make Cognito Forms actually pick an item from an array, you need to make it calculate something.

    I've tried putting any calculations within the usual array pick square brackets, but that doesn't work unless you are changing something on the form.

    So the only way that you can pick an item from an array using the usual split()[#] method would be to use this:



    • Input is the input field which will contain values that have the "Ð" symbol separating them.
    • ArrayItem is a separate input field that you will input whichever item from the array that you want.

    However that's imperfect, as I have to physically select that each time.


    Since it won't work how you'd think it should, one needs to use first last logic around the number that you want. In my tests, this works every time ... so if you wish to specify the number explicitly (example "3"):

    =Input.Split(['Ð'], 3).Last().Split('Ð').First()

    Or if you wish to have the number generated somewhere else:

    =Input.Split(['Ð'], Int32(ArrayItem)).Last().Split('Ð').First()

    What this does is:

    1. Limit the split to create only the number of items specified. In the above example that is "3".
    2. It then takes the last item, which will always contain unsplit data of at least 2 items.
    3. It then splits that last item again, taking only the first item.

    Used in an example:

    This logic (perhaps modified) should soundly allow you to select array items in any system (not just cognito forms) where your functionality would potentially be limited by system setup.

    So, to apply this to the original question, the answer would be to place the following in the Arraya field if I wanted the 4th item every time:

    =Inputta.Split(['#'], 4).Last().Split('#').First()

    Or add an ArrayItem field and use the following if I wished to pick an item from the list:

    =Inputta.Split(['#'], Int32(ArrayItem)).Last().Split('#').First()

    Obviously adding Custom Errors to ensure that any entries in ArrayItem are not larger than the Inputta.Split(['#']).Count().

    If you wanted to be flash you could even put a spinner on a ArrayItem and ensure that the minimum number is 1, and the maximum is =Input.Split('Ð').Count(). You could use this array picking to hide data in a field, and have this power much more complicated forms!

  • .Select() and .Where() are methods written for the repeating sections specifically. The only way to reference elements in an array on Cognito Forms is to use a bracket index.

    "aaa#bbb#ccc".Split("#")[0] would give you "aaa"

    "aaa#bbb#ccc".Split("#")[1] would give you "bbb"

    You can use an integer field instead of writing a number within that bracket.

Related Questions