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

207
Vistas
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 Respuestas
Responde la pregunta

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 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