Javascript To Bubble outputting multiple variables? How?

Hi there,

I’m starting to dig in to using the JavaScript to Bubble Toolbox plug in. I know a little bit about JavaScript and I’m having success passing variables INTO the J2B script, and I’m having success in retrieving an output from it to populate either a repeating group or a text element.

Question, some of my JavaScript functions will be producing numerous variables to output. How can I access more than one output from J2B properly?

Typically the proper way to set it up is to call the function at the bottom of the window with any values that are being passed OUT back to Bubble such as the following:

bubble_fn_functionTest(myVariable);

What if I have three variables that I want to access coming out of J2B such as myVar1, myVar2, myVar3? I may have three text elements that I want to populate with one of each for example.

What is the method for trying to access multiple values that live in my JavaScript function?

Thanks,
Dan

Perhaps answering my own question here, but I discovered that “Multiple values cannot be returned from a function in JavaScript but multiple values can be stored in an array or in an object and then the array or the object can be returned.”

Given this, if all of my values are numbers, then I can have a function that returns a list of numbers back to Bubble, and then I can can just reference them by position presumably.

If anyone has any other information feel free to chime in.

Thanks, Dan

2 Likes