Hello,
I would like to remove an element (the last one in my case) only by index. But Bubble doesn’t allow me to write :count-1
I didn’t find any solution on the forum.
There is a workaround here, but it doesn’t work for me.
I’m thinking of creating a specific state “count-1” where Bubble allow me to write :count - 1. But it seems quite complex for something that simple, am I missing something ?
I understand that is not quite an issue since the lists from Bubble don’t contain duplicates, but still.
@gaby beat me to it, but building on this a little further:
If I read you right, you have a list (let’s call it THE_LIST) and you want to turn that list into the same list… just without the last item. Correct?
If so, that’s just:
THE_LIST :minus item THE_LIST’s :last item
While Bubble isn’t a 100% array-oriented language, it gets some parts right, and this is one of them.
(Similarly, to answer the question posed in your post’s title: to remove an item by its position (1-based index) in THE_LIST, you simply do:
THE_LIST :minus item THE_LIST’s :item # position
And if this syntax seems strange to you… Well… This is syntactically a bit more straightforward than the JavaScript .slice() method, right?
It is slightly frustrating that you can’t nest THE_LIST’s :count (due to limitations - that are fully understandable when you look at them critically - in the expression builder) inside of an expression that already references THE_LIST. Well, that’s drag ‘n’ drop programming for you.
Nope, you are right…that is the way to do it if you don’t want to use a plugin for math.
I use the technique you mention with custom states a lot…I usually use them in conjunction with the current cell’s index values to set up some different behaviors with R.G. data.
My advice is be prepared to think outside of the box a lot when trying to force bubble to your will and get it to do what you want…you’ll usually prevail and find some way around the limitations.