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
}