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

246
Vistas
warning : function declared in a loop contains unsafe references to variable(s) ''
for (let i = 0; i < state.columns.length; i++) {
  var column = state.columns[i];
  var sortIndex;
  var fsColumn = firstSortColumns.find((v, i) => {
    sortIndex = i;
    return v.dataField === column.dataField;
  });
  if (fsColumn) {
    //...
  } else {
    //...
  }
}

Function declared in a loop contains unsafe references to variable(s) 'sortIndex', 'column'.

I am getting a warning like this, how can i fix this?

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

0

Your linter is being overly cautious here. Since the function you pass to find isn't called asynchronously, the fact the value of column can change isn't a problem.

If it were async then you could solve the problem by using let instead of var since it has block-scope instead of function-scope (and doing so would shut up your linter).

about 4 years ago · Juan Pablo Isaza Denunciar

0

Declare variables outside of the iteration (loop) and modify inside the for loop.

var column, fsColumn, sortIndex;
for (let i = 0; i < state.columns.length; i++) {
   column = state.columns[i];
   sortIndex;
   fsColumn = firstSortColumns.find((v, i) => {
    sortIndex = i;
    return v.dataField === column.dataField;
  });
  if (fsColumn) {
    //...
  } else {
    //...
  }
}
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