user2237168
user2237168

Reputation: 303

Using the contents of an array outside a function

Is there a possibility to use the contents of an array in another function? For example, I have the following code:

var locations = [];

function values() {
 var values = ['test1','test1']
 for (i in values) {
   locations.push(values[i]);
 }
}

Logger.log(locations)

Now it logs nothing, but if I place the logger in the function, it returns the contents of the array.

Upvotes: 0

Views: 55

Answers (1)

Sachin K
Sachin K

Reputation: 394

call function values(); like this

var locations = [];
values();

function values() {
 var values = ['test1','test1'];
 for (i in values) {
   locations.push(values[i]);
 }
}

Logger.log(locations);

Upvotes: 2

Related Questions