The next level question "is how can I figure out what is more optimal". Learning to profile your code is a huge benefit. Also, with questions like this you need to know what you are optimizing for memory, cpu, network speed, etc. If the ... is n API calls you have other concerns then if it is say file writes.
You should look into forEach, map or reduce. All of which solve specific cases for array iteration.
In the end this would be considered a micro optimization. Just get the coding done and refactor. Variable set vs function calls like size should not matter too much.
On the topic of array iteration and array functions, I would highly recommend that you take a minute to really look through the array prototype methods: developer.mozilla.org/en-US/docs/W...
There are several you may never end up using but having high level knowledge of the common ones (namely, forEach, map, filter, and reduce) is always useful. As Ryan has stated, the optimizations you're looking to make will save you a minimal amount of fetch/processing time at best.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The next level question "is how can I figure out what is more optimal". Learning to profile your code is a huge benefit. Also, with questions like this you need to know what you are optimizing for memory, cpu, network speed, etc. If the ... is n API calls you have other concerns then if it is say file writes.
You should look into forEach, map or reduce. All of which solve specific cases for array iteration.
In the end this would be considered a micro optimization. Just get the coding done and refactor. Variable set vs function calls like size should not matter too much.
On the topic of array iteration and array functions, I would highly recommend that you take a minute to really look through the array prototype methods: developer.mozilla.org/en-US/docs/W...
There are several you may never end up using but having high level knowledge of the common ones (namely, forEach, map, filter, and reduce) is always useful. As Ryan has stated, the optimizations you're looking to make will save you a minimal amount of fetch/processing time at best.