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

155
Vistas
How do I extract the unique values of a column to use them as a parameter in a function?

I am trying to pass to a function one parameter, coming from an array like:

const array=[1,2,2,3]

I do not want to introduce manually every time my list of parameters, so I am fetching the data I want from a spreadsheet, getting the unique values of the column. These would be my desired array.

However, I get this error in function generate_Form_links(af_col):

TypeError: Cannot read property 'forEach' of undefined

Here I get the column I want:

function getByName(colName) {
  const data=SpreadsheetApp.openById('1jogNOhdamVMXAlGyYOn9RXA2vNbrzNNJBUGhbL-EhTU').getSheets()[0]
  const [hA, ...vs]=data.getRange('E1:E13').getValues();
  let idx={};
  hA.forEach((h,i) => {idx[h]=i;});
  let oA=[];
  oA=vs.map(r=>r[idx[colName]]);
  Logger.log(oA.join('\n'))
  
}



var af_col=getByName('AF')

what could be wrong??

My function where I pass the parameter is:

function generate_Form_links(af_col){

  af_col.forEach(function(e, index){
    console.log(e, index)
    createForm(e)  //other function that create forms for each element of the given array  
  })
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Perhaps this simple example will be of some value.

Sheet0:

COL1 COL2 COL3 COL4 COL5
1,1 1,2 1,3 1,4 1,5
2,1 2,2 2,3 2,4 2,5
3,1 3,2 3,3 3,4 3,5
4,1 4,2 4,3 4,4 4,5

The Code to extract all values in COL3

  function getByName(colName) {
    const ss = SpreadsheetApp.getActive();
    const sh = ss.getSheetByName("Sheet0");
    const [hA, ...vs] = sh.getRange(1, 1, sh.getLastRow(), sh.getLastColumn()).getValues();
    let idx = {};
    hA.forEach((h, i) => { idx[h] = i; });
    let oA = [];//output array
    oA = vs.map(r => r[idx['COL3']]);
    Logger.log(oA.join('\n'))
  }

Execution log
4:50:57 PM  Notice  Execution started
4:50:58 PM  Info    1,3
2,3
3,3
4,3
4:50:58 PM  Notice  Execution completed
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