Dennis
Dennis

Reputation: 1169

Returning an array in Google Apps Script

I am trying to create a function that returns a two-element array value in Google Apps Script. Apparently I have misunderstood something because I thought that would be a simple matter of specifying:

      return [ value1 ][ value2 ] 

at the end of the function, but that is not working for me. So as a proof of concept, I wrote the following:

function testReturnArray() {
      var theValue = returnArray();
      Logger.log(theValue);
      }

function returnArray() { return ["a"]["b"]; }

When I run this code through the debugger, the log written is:

6:33:08 PM  Info    null

Clearly that's not my intended result. Can you please point me to the problem? I really would like to have two values returned from this function, and this is the easiest way I could think to do that. (Alternative being to return a class, but that may be overkill for my goal, and may also have a similar issue.)

Upvotes: 1

Views: 2128

Answers (1)

Diego
Diego

Reputation: 9571

That's not how you write arrays in JavaScript. You need to use a comma to separate the values. There's a lot of content explaining arrays, but I'll suggest this as one to start with.

var theValue = returnArray();
console.log(theValue);

function returnArray() { return [ "a", "b" ]; }

Upvotes: 2

Related Questions