Skip to main content
added 41 characters in body
Source Link
TheAddonDepot
  • 9.1k
  • 3
  • 25
  • 36

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. So the array only has 4 elements but your for loop tries to reference a 5th element that does not exist.

Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];[],
    region = '[some-region-value]';

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. So the array only has 4 elements but your for loop tries to reference a 5th element that does not exist.

Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. So the array only has 4 elements but your for loop tries to reference a 5th element that does not exist.

Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [],
    region = '[some-region-value]';

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});
added 181 characters in body
Source Link
TheAddonDepot
  • 9.1k
  • 3
  • 25
  • 36

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. Simplest So the array only has 4 elements but your for loop tries to reference a 5th element that does not exist.

Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. So the array only has 4 elements but your for loop tries to reference a 5th element that does not exist.

Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});
added 181 characters in body
Source Link
TheAddonDepot
  • 9.1k
  • 3
  • 25
  • 36

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];

range.getValues().forEach(function(row){
    options.push(row[0]);
});

Your bug stems from your for loop; it expects to iterate over 6 rows (i starts at 0 and increments by 1 up to 5), when what you really want is to iterate over 4 rows matching the range A3:B6. Simplest solution is to use the Array object's built in array methods (I'm using forEach in this case) to iterate over the items specifically in the range you defined as follows:

var range = sheet.getRange("A3:B"), // you automatically reference the last row with A3:B, no need for A3:B6
    options = [];

range.getValues().forEach(function(row){
    row[1] == region && options.push(row[0]); // exploit short-circuit mechanism in logical AND operator (in this case the operand on the right, the push, only gets executed if the operand on the left is true)
});
Source Link
TheAddonDepot
  • 9.1k
  • 3
  • 25
  • 36
Loading