Can someone tell me why these variables marked with red are not recognized as equal (==
).
Asked
Active
Viewed 42 times
-2

andrewJames
- 19,570
- 8
- 19
- 51
-
What is this supposed to be? – Ken Sharp Jun 24 '21 at 17:14
-
Side note: I recommend using `===` and `!==` instead of `==` and `!=`. See the discussions here: [Which equals operator (== vs ===) should be used in JavaScript comparisons?](https://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons) – andrewJames Jun 24 '21 at 17:43
2 Answers
0
Google Apps Script is Javascript-based. In Javascript, you can not compare two arrays using ==
.
One method is to loop over both arrays and to check that the values are the same. For example you can include the function:
function compareArrays(array1, array2) {
for (var i = 0; i < array1.length; i++) {
if (array1[i] instanceof Array) {
if (!(array2[i] instanceof Array) || compareArrays(array1[i], array2[i]) == false) {
return false;
}
}
else if (array2[i] != array1[i]) {
return false;
}
}
return true;
}
And then update the line in your code from if (responsables == gestPor) {
to if (compareArrays(responsables, gestPor)) {
For other methods of comparing arrays in Javascript, see this answer.

cbrxyz
- 105
- 5
0
It is because you are comparing arrays. If you are just getting a single cell value, use getValue()
instead of getValues()
To make things work, change these:
var gestPor = hojaActivador.getRange(i,13,1,1).getValues();
var responsables = hojaConMails.getRange(1,n,1,1).getValues();
to:
var gestPor = hojaActivador.getRange(i,13).getValue();
var responsables = hojaConMails.getRange(1,n).getValue();
Do these to all getValues()
where you're only extracting 1 cell/value.

NightEye
- 10,634
- 2
- 5
- 24