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

166
Vistas
Checking with Array[index] multiple times vs setting it a variable and using it - JAVASCRIPT/NODE.JS

I have a bunch of if statements and setting/adding different props into my array. My javascript code is like;

for(var key in animals){

if(animals[key].eyesColor == "blue"){

  animals[key].hairColor = "yellow"  
  ...

  ...

  } 
}

As I checked, I'm using 78 times animals[key].props And my array probably contains more than 1000 items.

Should I set the animal[key] to a variable and then set back this variable to my sample array at the end of my code? In this way can I improve the performance?

for(var key in animals){

let animal = animals[key]

if(animal.eyesColor == "blue"){

  animal.hairColor = "yellow"

  ...
  ...
  }

animals[key] = animal

}
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