"for" loop using javascript to bubble

Hi,

I am trying to run a simple javascript for loop in bubble. When I click a button a javascript to bubble gets fired which has a for loop,

let x = 3;
myList = [];
for(i=0; i<x; i++){
myList.push(i)
}
bubble_fn_function(myList);

I am trying to get the for loop to write the values 0,1,2 (as an array or otherwise) in the database and output to screen using a repeating group. I am not getting anywhere with it. Is this possible or am I doing something wrong? Or is there a better way to do this? Basically I just want to pass the output of a for loop which has multiple values to bubble and display using a repeating group. Any help would be appreciated.
Thanks,
George.

1 Like

Hi! What is the problem?

  1. You are not being able to GET this values outside JavaScript component? Or

  2. You are not being able to use it in a RG?

Hi rpetribu,
Thanks for your time. I basically want to run a for loop using “javascript to bubble”, say,
for(i=0; i<10; i++){
bubble_fn_foo(i);
}
and be able to pass and display 0, 1, …9 using a repeating group (or a better way), Sorry, I am still new to bubble and trying to figure out how to use javascript in bubble.

Thanks,
George.

So…

  1. Generate you Javascript:

let x = 3;
myList = ;
for(i=0; i<x; i++){
myList.push(i)
}
bubble_fn_function(myList);

  1. Pass the result list to Bubble:

  1. Now you have a list. You can check it out thru a simple text field like this:

image

It will display “0, 1, 2”

  1. Use it as a RG:

This is the result:

image

1 Like

Many Thanks, works fine…All good now.

1 Like