Currently, I am attempting to navigate through a spreadsheet column while disregarding any duplicate values. My approach involves using TextFinder to gather all cells with matching values and then adding them to an array named "duplicates."
Throughout each iteration, I have an if statement that checks if the current cell is included in the "duplicates" array. If it is, the program should proceed to the next iteration. However, despite my efforts using both "includes()" and "indexOf()", the condition does not seem to work as intended.
Below is the code snippet:
let duplicates = [];
for (let row = 1; row <= range.getNumRows(); row++) {
const cell = range.getCell(row, 1);
const value = cell.getValue();
if (!duplicates.includes(cell)) {
let array = range.createTextFinder(value).findAll();
const cellIndex = array.indexOf(cell);
array.splice(cellIndex, 1);
duplicates.push(...array);
}
}
I am unsure why this logic is not functioning correctly. As a newcomer to coding, I acknowledge that this may be due to a beginner's error.
Any assistance provided would be greatly appreciated! Thank you!