Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda