Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
Verify if cell exists in array of cells

I'm trying to iterate through a spreadsheet column while skipping the duplicated values. To do so, I use TextFinder to get all the cells with identical values and I add them to a "duplicates" array.

At every iteration, an if clause verifies if the current cell is part of the "duplicates" array and if so, it should just skip to the next iteration. However, it isn't the case; it proceeds through my if clause. I tried both "includes()" and "indexOf()".

Here's my code:

let duplicates = [];
    for (let row = 1; row <= range.getNumRows(); row++) {
      const cell = range.getCell(row, 1);
      const value = cell.getValue();

      if (duplicates.includes(cell) == false) {
        let array = range.createTextFinder(value).findAll();
        const cellIndex = array.indexOf(cell);
        array.splice(cellIndex, 1);
        duplicates.push(...array);
      }
    }

I'm honestly not sure why it doesn't work. However, I'm new to coding and it's probably a beginner's mistake.

Any help is appreciated! Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you're only trying to find the unique values of a column, try:

function uniqueValuesOfColumn() {

  return [...new Set(
    SpreadsheetApp.getActiveSpreadsheet()
                  .getSheetByName(`Sheet1`)
                  .getRange(`A:A`)
                  .getValues()
                  .flat()
                  .filter(Boolean)
  )]

  /* Or

  const uniqueValues = [...new Set(
    SpreadsheetApp.getActiveSpreadsheet()
                  .getSheetByName(`Sheet1`)
                  .getRange(`A:A`)
                  .getValues()
                  .flat()
                  .filter(Boolean)
  )];

  */

}

This converts all values of a column, with empty cells removed, into an array of unique values. This is done by 'converting' a Set of values into an array.

  • Set - JavaScript MDN
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda