I'm trying to filter CSV data by comparing it to an existing google sheet. This is the code:
var ss = SpreadsheetApp.getActive();
// get booking ID
var idList=ss.getSheetByName("Umsatzliste").getRange("G:G").getValues();
var filteredCSV=[];
for ( var i=0, lenCsv=csvData.length; i<lenCsv; i++ ){
if (idList.indexOf(csvData[i][6].toString())!=-1) {
filteredCSV.push(csvData[i]);
}
}
csvData=filteredCSV;
The indexOf()-function never seems to work out. csvData is a 2d-array with all csv-values:
ss.toast("ID#1: "+idList[0]+" ID#2: "+csvData[2349][6]+" - "+(idList[0]==csvData[2349][6]).toString());
returns
ID#1: MC/000002674 ID#2: MC/000002674 - false
Alright, the typeof reveals they are both "objects", so i try convert the csvData to a string value:
ss.toast("ID#1: "+idList[0]+" ID#2: "+csvData[2349][6]+" - "+(idList[0]==csvData[2349][6].toString()).toString());
which returns:
ID#1: MC/000002674 ID#2: MC/000002674 - true
So a comparison works. Any idea why indexOf() doesn't work?