There's no golden rule, each of these are a different tool the should be used at the right time.
Do you want a new instance of an array after your manipulation, without editing the original? You should use map, filter, reduce, etc. Since these are creating new instances of arrays during their computation, they should be avoided during uses cases of extreme space/time requirements.
Do you need to edit an array in place? For loops with push/pop is a fine solution.
The only one I generally do not use is .forEach. I think a for...of is more readable.
Arrays in general among the most powerful tools in JS. We should be leveraging these to their full extent!
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.
There's no golden rule, each of these are a different tool the should be used at the right time.
Do you want a new instance of an array after your manipulation, without editing the original? You should use map, filter, reduce, etc. Since these are creating new instances of arrays during their computation, they should be avoided during uses cases of extreme space/time requirements.
Do you need to edit an array in place? For loops with push/pop is a fine solution.
The only one I generally do not use is
.forEach
. I think afor...of
is more readable.Arrays in general among the most powerful tools in JS. We should be leveraging these to their full extent!