How to iterate the list using Toolbox

This is indeed an annoying deficiency in Bubble - i.e. that there’s no simple way to get the index of an item in a list. (You can access the index of a cell in a repeating group but not of an item in a list.)

The good news is that there’s a very clever pure-Bubble work-around. There is no need for a RG, no need to iterate, no need for a plugin, and no need for Javascript. Kudos to @vovazk for coming up with it.

By way of overview… Given a list and a thing in that list, you can determine the index of that thing by:

  1. Formatting the list as text where each item is the boolean result of comparing the thing to that list item.
     
    This step gives you a string like “nnynnn”.

  2. Using regex, truncate the string to preserve everything up through the first “y” - i.e. lop off everything after the first “y”.

  3. Count the characters in the truncated string, and voila, you have your index.

Of course, it’s silly to have to jump through such a hoop to get something as simple as a list index, but until Bubble adds the capability, this is one way to go about it.

:slightly_smiling_face:

1 Like