1

I am writing a Google form using a script so that I can pull the data from a Google spreadsheet and generate a page for each event based on a list of events which are of unknown length.

I have worked out that I can create the pages I need using this loop, with my list of events, eventvalues:

for (var i = 2; i < eventvalues.length; i += 1)
{
    var page = form.addPageBreakItem().setTitle(eventvalues[i][0]);
} 

I would like to end up with variables Page1, Page2, Page3, etc... all the way to eventvalues.length

Currently the variable page is used by the last page only and all others are not assigned to a variable because of being re-assigned.

1
  • I'm doing some spring cleaning and noticed you hadn't accepted my answer (which appears to be correct). If you're okay with it, do you mind accepting it? Commented Jul 31, 2017 at 21:34

2 Answers 2

5

You could use an array to store the pages.

var pages = [];

for (var i = 2; i < eventvalues.length; i+=1){
  pages.push(form.addPageBreakItem().setTitle(eventvalues[i][0]));
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the eval function.

    for (var i = 2; i < eventvalues.length; i+=1){
        eval("var page" + i + " = " + form.addPageBreakItem().setTitle(eventvalues[i][0]+";");
   } 
console.log(page1,page2,page3,page4,page5);

1 Comment

Eval is one of the quickest way to introduce errors and security issues into your JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.