I need to compare two variables in a loop and I am using the code below. It does not work. It seems that the code cannot find when the two variables are the same. I am not sure why.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet3 = ss.getSheetByName("Approved");
var sheet4 = ss.getSheetByName("ADD/REMOVE");
var list2 = sheet4.getRange(2,4,sheet4.getLastRow()-1,1).getValues();
var list3 = sheet3.getRange(2,8,sheet3.getLastRow()-1,1).getValues();
for(var i = 0;i<list2.length+1;i++){
for(var j=0;j<list3.length;j++){
var x = list3[j];
var y = list2[i];
console.log(x);
console.log(y);
if(x == y){sheet3.getRange(j+2,9).setValue("OK");console.log("HELLO!");}
}
}
I added the console messages to debug. "HELLO" is not there --> x is never equal to y. However, it should. Even the console shows x and y are equal when j = 8.
The code does not give an error, it just does not find when x = y. The values I am comparing are strings (emails)
Is there something wrong with code?
UPDATE: Solved by changing to:
var x = list3[j][0];
var y = list2[i][0];