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

216
Vistas
Efficiency of `num[i] = i` vs `num.push(i)` in JavaScript

I was curious (and had nothing to do) and decided to run a benchmark with the following for adding items to arrays:

var num = [];
for (var i = 0; i < 1000; i++) {
  num.push(i);
}

seems to be 90% slower than

var num = [];
for (var i = 0; i < 1000; i++) {
  num[i] = i;
}

The positions of the items do not matter to me in this case (as long as they are added to the array).
Can anyone explain why Array.prototype.push() is so much slower? You can find the benchmark here.

about 4 years ago · Juan Pablo Isaza
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