Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda