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

91
Vistas
Can anyone tell me that why the {For} Loop in JavaScript is returning all the values including the very first element of the an array?
var arr = [1,2,3,4,5]
for (var i=0; i<arr.length; i++){
    console.log(arr[i]);
}

I ran this code on google chrome console and the output was like this:

1
2
3
4
5

In this code I can see that all the elements are been printed but the very first element of the array which is 1 should not print because the value of [i] has already been incremented to 1 and so 2 should be printed instead of 1.
Can someone tell me why is this happening ?

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

0

I think you are getting it wrong here. In for loop, we have

for(initialization, condition, change) {
 // body
}

So, it workes in this sequence

initialization -> condition -> body -> change

PS: It will go to body if condition evaluates to true

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