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

204
Views
Does it make a difference (speed-wise) if i pick an object by index or via „find“ from an array?

The title pretty much descripes it. I got an array of days, sorted by the date. So the 1th of the month would be month[0].

When i pick these days in a loop, would it be faster to do this by

month.find(day => day.date === date)

Or

month[date-1]

Thank you for help :)

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

It does make a difference. When you use a direct index to look up the associated item, the computational complexity is O(1) - the engine just needs to look at the item at that single index and it finds it. But when you use .find, you go through every element of the array and call the callback on each one, only stopping once the found object passes the test.

That said, you'd only notice a difference if you were doing this sort of thing with a huge array and/or in a very tight loop. The difference will be utterly imperceptible most of the time.

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