0

Let's say I have a script that runs a for loop that outputs x number of new script lines depending on what a user answers. This script's main purpose is to construct an outgoing SOAP message with defined parameters. The for loop creates additional parameters to add to the existing parameters that are hardcoded into the script. How do I add these new parameters from the for loop to the script? Basically, add lines of script within the script (print to the script)... I can include the script if need be.

Thanks!

1 Answers1

0

You can use arrays with array.push(element) to make this happen. Arrays are incredibly powerful for processing like what you're describing, and we use them in our app for this purpose.

var scripts = [];

for(var i=0; i < data; i++) {
  scripts.push(data[i]);
}

Then if you need a single string at the end you can use join like this scripts.join(). Note that you could also add line returns if you want too.

However, it sounds like you do want to process the results of the scripts in order, at which time you can just loop through that array and send the parameters to another function one at a time.

There are a lot of functions in the array object that will help with what you're trying to do. Here is a link to the MDN docs for your reference.

Graham
  • 7,431
  • 18
  • 59
  • 84