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

232
Vistas
iterate for each element of variable, got TypeError

I would like to do something for each element in my_var:

// get selected rows of DataTable
let table_data = dtMember.rows({ selected: true }).data();
const COL_INDEX = 4 ; // column index of the column to count
let my_var = table_data.reduce(function (col_to_count, currentValue) {
    if (currentValue[COL_INDEX] in kulturen) {
        col_to_count[currentValue[COL_INDEX]]++;
    }
    else {
        col_to_count[currentValue[COL_INDEX]] = 1;
    }
    return col_to_count;                            
}, {});   

I tried:

for (const element of my_var) {
    console.log(element);
}

But getting the

TypeError: my_var is not eterable

I tried also my_var.entries() and my_var.keys() which are suggested on the help page of firefox but let to is not a function

How can I do it correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use in for Objects. of is for iterating over Arrays.

for (const key in my_var) {
  console.log(key, my_var[key])
}
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