Get the index of an item in a list

Is there a way to get the index of a specific item in a list?

So internally a list is like
[1]=red
[2]=blue
[3]=green

If I already have the item number (like 2) I can use it to return “blue” with :item #
But what how do I find the item number in the first place?

Specifically, I’ve got a repeating group that of course has a list of data. I’d like to number each cell of the repeating group according to its position. So that the first cell has a (1) in it and the second cell has a (2) in it and the third cell has a (3) in it and so on. It seems like I should be able to just grab the index of the current cell, but I don’t see an expression to get that information.

3 Likes

You can use “item #” to retrieve a specific item in a list and you should definitely have an option for “current cell’s index”

(sorry, hit send way too fast, but these 2 should be what you’re looking for)

2 Likes

Huh, neat! I never noticed that before. Maybe because that option doesn’t appear for any element that’s in a group in the cell. I only see it for elements that aren’t grouped.

You can see that this text, which is inside of group Action_Header, only has access to its parent group’s action, not to the cell it’s in.

However, this random text element I added as a test does have access to the cell’s index as long as it’s not grouped

Yep, you’re right. Has to be at the top level to get it. I’m not sure why we can’t have access to the cell index from any nested element within…

@emmanuel would this be an easy addition?

My guess is that the current naming convention would make it a bit confusing in nested cases (e.g. which of the two “Current cell’s index” refers to current, as opposed to parent, cell.

Isn’t there only the one cell? Everything in the cell is in the “current” cell. The cell is its own thing, distinct from a group.

In the case of nested repeating groups, the current cell could be from the current repeating group, or the parent repeating group.

Oh, yeah, that’s a good point.

Seems like the current expressions should be able to handle that now. Something like “the current cell’s current cell’s current cell” makes just as much sense as the expressions I’m already building.

1 Like

I’ve had multiple RGs nested within cells before, so this is a good point. That could get confusing quick.

I’d want to better identify a specific cell than just current cell’s current cell or parent group’s parent group’s cell…

1 Like

Hi, I have exactly the same question, but I am not using a repeating group.
I am using a list in an external API, and I want to find the # Index of a specific element in this list (let’s say “Blue” in the example above).

I am not storing this list into a database, just using it as a data API list.

1 Like

Take a look at this post - Toolbox plugin - collection of utility elements

1 Like

Thanks! I’m not good at using JS but I will give it a try.
Do you think it will also work with a data API list instead of a search into database?

1 Like