Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!