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

252
Vistas
How to skip first iteration in javascript for-of loop

I know how to skip first iteration in javascript foreach loop

dataObject.slice(1).forEach((row) => {});

I want to know how to do the same thing using for of loop in javascript, please help me, thanks

for( const row of dataObject )

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

0

The same way you're skipping it with forEach - replace the dataObject expression with dataObject.slice(1).

for( const row of dataObject.slice(1) )
about 4 years ago · Juan Pablo Isaza Denunciar

0

While CertainPerformace's solution is what most people, including me, would go with, it does have a the downside of having to make a temporary array copy, which would be bad when you have huge arrays (but completely unnoticeable usually).

To prevent copying the array, create a temporary variable to check if it's the first in the loop. The downsides of this is the temporary variable, and the if check on every iteration could make it slower.

let first = true;
for (const row of dataObject) {
  if (first) {
    first = false;
    continue;
  }
  // ... rest of script
}

And I would probably just use a traditional incremental for-loop anyways if you want more control over iteration, since forEach, for-of, and for-in are meant to iterate over everything.

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