Quick question!

I’ve been searching how to iterate a dynamic list variable inside of “Run Javascript” action, but no luck on this.

I feel like this is a very common thing to do when messing with “Run Javascript” action. How people do this?

image

Run JavaScript runs eval() on the text input. So you just render whatever value you want as text. An array in JavaScript is specified with square brackets, so if you’re trying to send an array, you format your dynamic expression to output text that looks like this (in my example, let’s use an array of numbers):

[1, 3, 5, 7, 9]

An array of strings would need to look like:

[‘one’, ‘three’, ‘five’, ‘seven’, ‘nine’]

The spaces between the commas don’t matter. BTW.

I meant I can’t use var i inside of dynamic variable.

This comment doesn’t make sense.

I want to iterate the list of objects from my API response, but I can’t figure how I can do that within the “Run javascript” action.

I’m pretty sure I gave you the answer. Arrays are iterable.

I understand array is iterable but not the list of object (yellow highlighted part). The object has some member variables I want to use for each loop. I can’t put it like this knowing that the action is using eval().
image

Could you please show a code snippet how I can use array to iterate the object list?

It has to resolve to a string. As I said before. Because eval().

How to convert the dynamic variable of object to string?

In the usual way, using :formatted as or other text transformations, as needed.

Hi Keith, I still don’t get how I can iterate the dynamic list on “run javascript” action.

I’m trying to do something like:

for (let i = 0; i < count; i ++) {
  let elem = some_dynamic_list[i];  # No idea how I can do this on bubble
  
  # <do something with elem>
   ...
}

You mentioned an array and eval() from the previous answers, but I don’t know how they are related to the iteration.

Can you format your list to look like an array? Do that. I’m sorry to be cryptic, but I’m not the sort to delve deeply into your problem. I just tell you how to solve it. There’s no compensation in any of it, so why spend any time on it? (Believe me, I have to restrain myself from helping further.)

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