Any idea on how to show the second to last item in a list of things? There is an option to view the last item and the first item but i can’t figure out how to display the second to last. It seems so simple but i can’t figure it out.
I tried “:count -1” but it wouldn’t let me. Thanks for your ideas!
This doesn’t work - sorting reorders the list alphabetically, not by the actual position of an element in the list. I could really use a nice way to get the second to last or nth to last item in a list
We’re trying to get the nth from last item. Not all items from n to the end of the list. So second from last item would be the 6th element from a list with 8 items or the 7th item in a list of 9. But we don’t know how many items the list has… Doing List Count - 1 doesn’t work in bubble
You can precompute the item number of the second to last item in some_list as:
Set some_state to some_list:count - 1
^^^ this is an expression you can build
Then, the second to last list item is:
some_list:item# some_state’s value
However, you cannot build the expression:
some_list:item# some_list:count - 1
Because:
some_list:item# some_list:count
resolves to an object of some_list’s type and does so before evaluating anything further to the right.
You cannot force Bubble to evaluate (count - 1) in-line with the :item# operator. That’s not a thing you can do.
Now, if some_list is of type number, you CAN construct:
some_list:item# some_list:count - 1
But that expression does not yield the number stored in the second to last item of some_list. That expression yields [edit] the VALUE held in the LAST item in the list minus one. (So If last item holds 10 this yields 9.)
@keith, nice explanation. That is why I think that Bubble may need to provide interface for accessing n-th item from the last position. Although, if only few of the users want it it does not make sense to do it. This page can be an indicator if it is wished or not.