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

135
Views
Comparing array length with iteration variable in for loop returns wrong result

I have the following code:

var numbers = [1,2,3,4]

for (var x = 0; x < 8; x++) {
    console.log(x, numbers.length, x >= numbers.lenght)
}

Now, what I want to do here is detect when x is bigger or equal to the array length. When I run this program, I get the following result:

0, 4, false
1, 4, false
2, 4, false
3, 4, false
4, 4, false
5, 4, false
6, 4, false
7, 4, false

Why does my query return false even tho x is bigger after the fifth iteration?

Fiddle: https://jsfiddle.net/j9eyqkvb/16/

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