How to transform Bubble list into a Javascript Array

Hi! I am using the Toolbox to save an array into an object in Bubble (as a list).

The problem is that the array is something like:

[“Car”, “Plane”, “Boat”]

And the list is something like:

Car, Plane, Boat.

So when i try to read this list back into my workflow, and transform it into an array, it became a single element such:

[“Car, Plane, Boat”]

How can i put this list back into javascript and make it understand that every single element in the list is an element in my array?

You use JavaScript to Bubble, of course to return your JavaScript array to Bubble. Configure your JS to Bubble as a list of texts type.

When you call its function from Run JavaScript, you pass your (properly formatted) JavaScript array as its argument.

Hi @keith .

I am having no problem with this. The problem is to make my javascript read back the list that i have stored in the “JavaScript to Bubble” element as an Array, because it was saved as a list.

But i have found a solution :slightly_smiling_face:

var lista = ["my_list's value list:items from #1 join with ",""]

This JavaScript converts the list into an array format.



Yep, that’s how you do that. (I guess I read your question backward, eh, @rpetribu?)

Note that don’t actually need the :items from #1 operator here as, by default, the text representation of this list will be all items, by default. (But you do need the :join, obviously, as the default join is comma-space, not quote-comma-space.) Whenever you’re constructing an expression like this, it’s helpful to first throw it into a text element so you can see what you’re building.

The way that Run JavaScript works is that it just runs JavaScript’s eval() function on the contents of the text input. So you’re literally just constructing the text of your script. Any Bubble expressions you write in that text input are evaluated by Bubble and spit out as text.

(This evaluation happens “right before” your workflow executes the Run JavaScript action – the input field is evaluated and that fully expanded string value is what is sent to the guts of the Run JavaScript action. Which just runs eval() on that string.)

Uff :fire:

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