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

105
Views
why all element of array printed instead of half array only

I was doing a task in JavaScript and I notice when i try to print only half array the final array is being printed. Here the code:

let a = [];
for (let i = 1; i < 5; i++) {
  if (i === 2) console.log(a)
  a.push(i)
}

Here in output instead of printing array with only 1 element it is printing array with every element from 1 to 5. My question is why this is happening?

about 4 years ago · Santiago Gelvez
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!