Change item in Custom State list by its position number

Hi.
I have a Custom State that is a long list of numbers (eg: 2, 1, 3, 2, 0, 2, 1, 0, 0, 2…)
I will later do some calculations by referring to each number by its position in the list.

However, sometimes I would like to change a specific item in that list by its position number.
Example: replace the number ‘1’ in the second position in that list with the number ‘0’.
The resulting list would then be: 2, 0, 3, 2, 0, 2, 1, 0, 0, 2…
Any way I can do that?

Thanks!

2 Likes

Hi!
Bubble list operations in general remove duplicates, so you’ll need to do this elsewhere, and javascript is a natural place to do this.
You can use HTML elements, or a plugin like Toolbox.

One limitation with plugins is that workflow steps don’t return a value, so you’ll need to split into two workflows:

Workflow step: Run javascript ;
var newlist = [custom state list];
newlist[1] = 0;
bubble_fn_newlist( newlist );

Javascript to Bubble event workflow:
set custom state list value to this element’s value.

I recommend this video by Keith …

5 Likes

Awesome!
This should work.
Good to know I can work with some simple JS in Bubble.
I guess I need to brush up on my JS skills but what I need should be simple and this video gives me all info I need.
Thank you mishav.
Cheers!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.