I've got this working code that removes duplicates by comparing values in column B. If row 2 and 3 have the same values in column B then row 3 is deleted.
function removeDuplicates() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var newData = new Array();
for(i in data){
var row = data[i];
var duplicate = false;
for(j in newData){
if(row[1] == newData[j][1]){
duplicate = true;
}
}
if(!duplicate){
newData.push(row);
}
}
sheet.clearContents();
sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
}
How can I change this code to build the array from edit this so that instead of row 3 being deleted, row 2 is deleted?